小编Fro*_*yre的帖子

为什么要编译:string = int

假设以下代码:

#include <iostream>
#include <string>

int func() { return 2; }

int main()
{
   std::string str("str");
   str = func();
   std::cout << "Acquired value: '" << str << "'" << std::endl;

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么行str = func();编译时没有出现类型不匹配的警告?

我正在使用编译器gcc v.4.7.1并设置-std = c ++ 11标志.

输出:

Acquired value: ''

c++ gcc stdstring c++11

6
推荐指数
1
解决办法
203
查看次数

标签 统计

c++ ×1

c++11 ×1

gcc ×1

stdstring ×1