即使使用带有 g++ 的 Ubuntu 上的“array”指令,也可以重现此错误:
例如,这个 C++ 代码:
#include <iostream>
#include <array>
using namespace std;
int main(){
std::array<int, 5> myints;
cout << myints.size();
}
编译并运行如下:
g++ -o s s.cpp
./s
打印错误:
/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This
file requires compiler and library support for the upcoming ISO
C++ standard, C++0x. This support is currently experimental, and
must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
s.cpp: In function ‘int main()’:
s.cpp:6:5: error: ‘array’ is not a member of ‘std’
解决方案:使用编译器选项编译它-std=c++0x
:
g++ -o s s.cpp -std=c++0x
./s
然后程序正确打印:
5