進入codeblocks,點擊Settings --> Compiler..,進入以下頁面ios
勾選「Have g++ follow the C++11 ISO language standard [-std=c++11]」並肯定。
能夠經過以下示例來查看效果:c++
#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; }