简体   繁体   中英

Lambda expressions support in VS2008 SP1

Is there support for lambda expressions from C++ 0x in Visual Studio 2008 SP1? Example below throws me syntax errors. Is there any '-Cpp0x' flag for compiler or something?

#include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>

using namespace std;

int main() 
{
  vector<int> v;

  for (int i = 0; i < 10; ++i) 
  {
    v.push_back(i);
  }

  for_each(v.begin(), v.end(), [](int n) { cout << n << " "; });
  cout << endl;
}

Thank you in advance.

See Stackoverflow question #146381

Simply put: no. Visual Studio 2010 will support C++0x to some extent, but I'm unsure if that will include lambda expressions.

You can... kind of.

The Visual C++ 2008 compiler doesn't support lambdas, but you can certainly use the Visual C++ 2010 compilers from Visual Studio 2008!!

Just install Visual C++ 2010 Express, and then open Visual Studio 2008 and go to:

Tools -> Options -> Project and Solutions -> VC++ Directories

and then add the following entries:

  • For the Win32 platform, insert $(ProgramFiles)\\Microsoft Visual Studio 10.0\\VC\\bin at the beginning , and $(ProgramFiles)\\Microsoft Visual Studio 10.0\\Common7\\IDE at the end .

  • For the x64 platform, insert $(ProgramFiles)\\Microsoft Visual Studio 10.0\\VC\\bin\\amd64 at the beginning .

Now you can use all the VC++ 2010 features from Visual Studio 2008! :)

Visual Studio不支持,而是使用Boost库。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM