Code::Blocks设置支持C++ 11

时间:2023-03-10 04:40:47
Code::Blocks设置支持C++ 11

进入codeblocks,点击Settings --> Compiler..,进入如下页面

Code::Blocks设置支持C++ 11
勾选“Have g++ follow the C++11 ISO language standard [-std=c++11]”并确定。
可以通过如下示例来查看效果:

#include <iostream>
#include <functional>
using namespace std;
int add(int a, int b)
{
return a + b;
}
int main()
{
function<int(int,int)> f = add;
cout << f(, ) << endl;
auto g = []{ return "Hello World"; };
cout << g() << endl;
int a[] = { , , , , };
for (const int & num : a)
{
cout << num << endl;
}
return ;
}