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

时间:2023-03-08 21:02:04

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 ;
}

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

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

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