用g+编译C+11

用g+编译C+11

我正在尝试将我的C+编译器更新为C+11。-std=c++0x-std=gnu++0x但我对旗子不太了解。有谁可以帮我?(我使用的是Ubuntu12.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编译器选项启用。


aluckdog
浏览 651回答 3
3回答

Smart猫小萌

标志(或编译器选项)只不过是传递给编译器可执行文件的普通命令行参数。假设从命令行(终端)调用g+:$ g++ -std=c++11 your_file.cpp -o your_program或$ g++ -std=c++0x your_file.cpp -o your_program如果上面的方法不起作用的话。

ABOUTYOU

你可以检查你的g++命令:which&nbsp;g++g++&nbsp;--version这将告诉你,哪个编辑目前是它的指向。切换到g++4.7(假设您已将其安装在计算机中),运行:sudo&nbsp;update-alternatives&nbsp;--config&nbsp;gccThere&nbsp;are&nbsp;2&nbsp;choices&nbsp;for&nbsp;the&nbsp;alternative&nbsp;gcc&nbsp;(providing&nbsp;/usr/bin/gcc). &nbsp;&nbsp;Selection&nbsp;&nbsp;&nbsp;&nbsp;Path&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Priority&nbsp;&nbsp;&nbsp;Status------------------------------------------------------------ &nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/bin/gcc-4.6&nbsp;&nbsp;&nbsp;60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;auto&nbsp;mode&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/bin/gcc-4.6&nbsp;&nbsp;&nbsp;60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;manual&nbsp;mode*&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/bin/gcc-4.7&nbsp;&nbsp;&nbsp;40&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;manual&nbsp;mode然后选择2作为选择(我的机器已经指向g++4.7,所以*)一旦你切换了编译器,然后再运行g++ --version以检查切换是否正确。现在用g++&nbsp;-std=c++11&nbsp;your_file.cpp&nbsp;-o&nbsp;main
打开App,查看更多内容
随时随地看视频慕课网APP