Foreach win32-g++;每个_和lambda上的错误

Foreach win32-g++;每个_和lambda上的错误,foreach,lambda,g++,Foreach,Lambda,G++,我知道这个主题经常出现在stackoverflow上,但这里的情况不同: 以下代码使用MsVC++2013编译,但不使用win32-g++。有没有办法使它同时适用于这两种编译器 #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { vector<int>my_vector; for(int i=0

我知道这个主题经常出现在stackoverflow上,但这里的情况不同: 以下代码使用MsVC++2013编译,但不使用win32-g++。有没有办法使它同时适用于这两种编译器

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;



int main()
{
    vector<int>my_vector;
    for(int i=0; i < 6; i++)
        my_vector.push_back(i);
    for_each( my_vector.begin(), my_vector.end(), [ ](int  n){cout<<n;});
    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
向量;
对于(int i=0;i<6;i++)
我的向量。推回(i);

对于_each(my_vector.begin()、my_vector.end()、[](int n){cout结果表明,-sdd=C++11是“默认启用”的语句误导了我。 我最终找到了一种方法,通过项目>构建选项>编译器设置来打开它 然后点击“复选框中有G+ + C++ 11的ISO C++语言设置”复选框。 对于正在使用QtCreator的用户,请在项目文件中添加以下行: QMAKE_cxflags+=-std=c++11

||=== stdtest, Debug ===|
D:\dev\CplusPlus\stdtest\main.cpp||In function 'int main()':|
D:\dev\CplusPlus\stdtest\main.cpp|13|warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]|
D:\dev\CplusPlus\stdtest\main.cpp|13|error: no matching function for call to 'for_each(std::vector<int>::iterator, std::vector<int>::iterator, main()::<lambda(int)>)'|
D:\dev\CplusPlus\stdtest\main.cpp|13|note: candidate is:|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_algo.h|4436|note: template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct)|
D:\dev\CplusPlus\stdtest\main.cpp|13|error: template argument for 'template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct)' uses local type 'main()::<lambda(int)>'|
D:\dev\CplusPlus\stdtest\main.cpp|13|error:   trying to instantiate 'template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct)'|
||=== Build finished: 3 errors, 1 warnings (0 minutes, 0 seconds) ===|