C++ 如何在visual studio 2010 express edition上启用C++11编译器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15865902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:50:19  来源:igfitidea点击:

How to enable C++11 compiler on visual studio 2010 express edition?

c++visual-studio-2010visual-c++c++11tbb

提问by Hello

I am using tbb::parallel_for function which make use of lambdas. I am getting syntax errors with the following code:

我正在使用使用 lambdas 的 tbb::parallel_for 函数。我收到以下代码的语法错误:

void parallel_relax( Class object, std::vector<Vertex *> verList ) {
    tbb::parallel_for (blocked_range<int>(0, verList.size()), [=](const blocked_range<Vertex *>& r) {
        for(Vertex *vit = r.begin(); vit != r.end(); ++vit) {
            Vertex *v = vit;
            object.function(v);
        }
    });
}

Syntax Errors:

语法错误:

syntax error : '['
1>main.cpp(16): error C2143: syntax error : missing ')' before '{'
1>main.cpp(16): error C2143: syntax error : missing ';' before '{'
1>main.cpp(17): error C2065: 'r' : undeclared identifier
1>main.cpp(17): error C2228: left of '.begin' must have class/struct/union
1>          type is ''unknown-type''
1>main.cpp(17): error C2065: 'r' : undeclared identifier
1>main.cpp(17): error C2228: left of '.end' must have class/struct/union
1>          type is ''unknown-type''
1>main.cpp(20): error C2059: syntax error : ')'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I think this is the problem with the compiler. How do i get c++11 compiler for visual studio 2010 express edition. Please suggest.

我认为这是编译器的问题。我如何获得 Visual Studio 2010 速成版的 c++11 编译器。请建议。

回答by Chris

Visual C++ 2010 Express does contain C++11 features, but not all of them. Here is a list of what features it supports (as well as VC++ 2012): http://msdn.microsoft.com/en-ca/library/vstudio/hh567368.aspx

Visual C++ 2010 Express 确实包含 C++11 功能,但不是全部。以下是它支持的功能列表(以及 VC++ 2012):http: //msdn.microsoft.com/en-ca/library/vstudio/hh567368.aspx

回答by chue x

To get C++11 features you should use the latest version, Visual Studio 2012.

要获得 C++11 功能,您应该使用最新版本Visual Studio 2012

From C++11 Features (Modern C++):

C++11 特性(现代 C++)

Visual C++ 2010 implemented many features in the C++0x core language specification, which was the precursor to C++11, and Visual C++ in Visual Studio 2012 expands on that to include many C++11 features.

Visual C++ 2010 在 C++0x 核心语言规范(C++11 的前身)中实现了许多功能,而 Visual Studio 2012 中的 Visual C++ 对此进行了扩展,以包含许多 C++11 功能。