$ ./testserver
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
已放弃
[shinow@localhost test]$ g++ testserver.cpp -o testserver
[shinow@localhost test]$ ./testserver
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
已放弃
[shinow@localhost test]$ g++ -std=c++11 -pthread testserver.cpp -o testserver
如果clion编译时,会报这种错误。需要在CMakeLists.txt修改编译选项。
g++ 4.7 才真正支持 c++11
g++编译时支持C++11
- //第一种,直接包含在源程序文件中,如第一行代码所示
- #pragma GCC diagnostic error "-std=c++11"
- #include <iostream>
- using namespace std;
- int main(int argc,char **argv)
- {
- cout<<"hello world!"<<endl;
- auto i=10;
- cout<<i<<endl;
- return 0;
- }
- //第二种方法,可以直接取别名方法 如下所示:
- alias g++='g++ -std=c++11'
- g++ hw.cpp -o hw