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

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


勾选“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(10, 20) << endl;
    auto g = []{ return "Hello World"; };
    cout << g() << endl;
    int a[5] = { 1, 2, 3, 4, 5 };
    for (const int & num : a)
    {
        cout << num << endl;
    }
    return 0;
}

 

posted @ 2016-08-11 10:41  月光诗人  阅读(618)  评论(0编辑  收藏  举报