目录
- 运行代码出现的错误
- 错误原因
- 解决办法
运行代码出现的错误
e:DesktopC++第六章>cd “e:DesktopC++第六章” && g++ array_test.cpp -o array_test && "e:DesktopC++第六章"array_test
In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/array:35:0,
from array_test.cpp:3:
C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the
^
array_test.cpp: In function ‘int main()’:
array_test.cpp:11:5: error: ‘default_random_engine’ was not declared in this scope
default_random_engine engine(static_cast(time(0)));
^
array_test.cpp:12:5: error: ‘uniform_int_distribution’ was not declared in this scope
uniform_int_distribution randomInt(1, 6);
^
array_test.cpp:12:30: error: expected primary-expression before ‘unsigned’
uniform_int_distribution randomInt(1, 6);
^
错误原因
cpp文件中包含C++11特有的内容
uniform_int_distribution
所使用的编译器不支持 ISO C++ 2011 标准。
解决办法
需要在编译命令中添加 -std=c++11 或 -std=gnu++11 选项来启用对该标准的支持。
g++ ***.cpp -o *** -std=c++11
注意:***处填写自己的文件名