ubuntu下使用g++编译时默认支持C++11 配置方法

1.只需要在源文件程序中加上如下一行代码:

1 #pragma GCC diagnostic error "-std=c++11" 

此时源文件代码如下:

#pragma GCC diagnostic error "-std=c++11"  //直接包含在源程序文件中
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cout << "请输入一个字符串:" << endl;
  getline(cin,s);
  for(auto &c : s)
  {
    c = 'X';
  }
  cout << s << endl;

  return 0;
}

2.编译时采用如下指令:

1 g++ -std=c++11 1.cpp -o 1  //加上 -std=c++11

然后终端 : ./1 运行就OK了

原文地址:https://www.cnblogs.com/ilym/p/8145008.html