我试图更新我的c++编译器到c++ 11。
我已经搜索了一点,我得出的结论是,我必须使用标志-std=c++0x或-std=gnu++0x,但我不知道很多关于标志的事情。有人能帮帮我吗?(我使用的是Ubuntu 12.04。)
以下是我试图使用c++ 11中包含的库(即数组)时从编译器得到的错误:
#include <array>
#include <iostream>
int main()
{
std::array<int, 3> arr = {2, 3, 5};
...
}
该文件需要即将发布的ISO c++标准c++ 0x的编译器和库支持。这种支持目前是实验性的,必须使用-std=c++0x或-std=gnu++0x编译器选项来启用。
如果你想保留GNU编译器扩展,使用-std= GNU ++0x而不是-std=c++0x。下面是手册页中的一段话:
The compiler can accept several base standards, such as c89 or c++98,
and GNU dialects of those standards, such as gnu89 or gnu++98. By
specifying a base standard, the compiler will accept all programs
following that standard and those using GNU extensions that do not
contradict it. For example, -std=c89 turns off certain features of GCC
that are incompatible with ISO C90, such as the "asm" and "typeof"
keywords, but not other GNU extensions that do not have a meaning in
ISO C90, such as omitting the middle term of a "?:" expression. On the
other hand, by specifying a GNU dialect of a standard, all features
the compiler support are enabled, even when those features change the
meaning of the base standard and some strict-conforming programs may
be rejected. The particular standard is used by -pedantic to identify
which features are GNU extensions given that version of the standard.
For example-std=gnu89 -pedantic would warn about C++ style //
comments, while -std=gnu99 -pedantic would not.
如果你想保留GNU编译器扩展,使用-std= GNU ++0x而不是-std=c++0x。下面是手册页中的一段话:
The compiler can accept several base standards, such as c89 or c++98,
and GNU dialects of those standards, such as gnu89 or gnu++98. By
specifying a base standard, the compiler will accept all programs
following that standard and those using GNU extensions that do not
contradict it. For example, -std=c89 turns off certain features of GCC
that are incompatible with ISO C90, such as the "asm" and "typeof"
keywords, but not other GNU extensions that do not have a meaning in
ISO C90, such as omitting the middle term of a "?:" expression. On the
other hand, by specifying a GNU dialect of a standard, all features
the compiler support are enabled, even when those features change the
meaning of the base standard and some strict-conforming programs may
be rejected. The particular standard is used by -pedantic to identify
which features are GNU extensions given that version of the standard.
For example-std=gnu89 -pedantic would warn about C++ style //
comments, while -std=gnu99 -pedantic would not.