#include <iostream> 使用 -std=c++11 给出错误
#include <iostream> gives error using -std=c++11
我在Windows上使用MinGW的gcc编译器。版本为4.9.3。当使用-std=c++98、-std=c++03或-std=c++11作为参数时,下面的代码会给出错误。
#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}
当-std=gnu++98, -std=gnu++03或std=gnu++11作为参数时,代码编译没有错误。此外,当不使用c++版本参数(g++ test.cpp -c)时,代码不会编译错误
进一步调查后,我发现这是#include引起的问题。以下代码在使用std=c++参数时不会产生任何错误:
int main()
{
return 0;
}
然而,当寻找其他东西来测试我的代码时,下面的工作:
#include <cmath>
int main()
{
return 0;
}
但这不是:
#include <string>
int main()
{
return 0;
}
怎么回事?通过对gnu++的简短搜索,它说它提供了额外的扩展,但是像上面这样简单的代码肯定不应该依赖于任何扩展?
我已经粘贴了用g++ test.cpp编译第一段代码时发生的大错误-c -std=c++11。http://pastebin.com/k0RLtWQz
第一个消息是:
$ g++ test.cpp -c -std=c++11
In file included from c:mingwincludewchar.h:208:0,
from c:mingwlibgccmingw324.9.3includec++cwchar:44,
from c:mingwlibgccmingw324.9.3includec++bitspostypes.h:40,
from c:mingwlibgccmingw324.9.3includec++iosfwd:40,
from c:mingwlibgccmingw324.9.3includec++ios:38,
from c:mingwlibgccmingw324.9.3includec++ostream:38,
from c:mingwlibgccmingw324.9.3includec++iostream:39,
from test.cpp:1:
c:mingwincludesys/stat.h:173:14: error: '_dev_t' does not name a type
struct _stat __struct_stat_defined( _off_t, time_t );
^
c:mingwincludesys/stat.h:173:14: error: '_ino_t' does not name a type
struct _stat __struct_stat_defined( _off_t, time_t );
^
…
通过更改为mingw64(也使用较新版本的gcc)解决。似乎问题出在我的mingw32安装或发行版上(正如Jonathan Leffler指出的)。所有-std=c++xx参数现在都可以工作了
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 尝试将 C++11 代码转换为 C++03 时默认函数模板参数出错
- 在旧的 c++ (<c++11) 中,初始化结构会出错
- 为 freebsd 11 编译 gcc4.8.5 时出错: 错误: 未知类型名称 'choke'
- 尝试在Linux上使用Clang++编译c++11 regex教程时出错
- 使用 C++11 复制构造 boost::shared_ptr 时出错
- 在 Ubuntu 13.10 x64 C++11 中创建 std::线程时出错
- 在 C++11 中使用 decltype() 时出错(在 gcc 4.7.0 中创建不透明的错误消息)
- 在 Windows 上使用 CMake 2.8.11 构建自定义 Qt 4.8.3 库时出错
- <dir> 因缺乏而跳过...尝试在 Ubuntu 1.49 上安装 Boost 11.04 时出错
- 在C++11中确定泛型返回类型时出错
- 在C++11中存储对方法的引用时出错
- 使用CUDA和C++11时出错
- 使用makefile和c++11编译时出错
- 在ubuntu 11.10上安装GCC 4.3.4出错
- 使用Matlab R2011a在Ubuntu 11.04上编译Matlab mex文件时出错
- C++11线程:将向量传递给线程函数时出错