怎样在Linux环境编译支持C11

我用的系统是ubuntu 14.04, g++版本是4.8.4的,是支持C++11,我自己一般最常用的的C++编译器是g++和eclipse

一,g++

g++ 在一般的编译命令中加入-std=c++11 ,如下

g++ -std=c++11 -o test test.cpp

二,eclipse

打开eclipse,依次设置

C/C++ Build > Settings > GCC C++ Compiler > Miscellaneous > other flages 加 -std=c++11 或 c++0x

对于GCC C compiler, 相似的添加-std=gnu++11 然后点击 Apply。

如下程序可以测试是否,用C++11修改过的auto特性

  #include <iostream>
  using  namespace std;
  
  int main()
  {
      auto a = 10;
      cout << "%d\n",a;
      return 0;
  }

编译成功,即为设置成功.




你可能感兴趣的:(C++11)