如何在 Visual Studio 2010 中“激活”c++11 标准?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19857263/
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 23:12:18  来源:igfitidea点击:

How to "activate" c++11 standard in visual studio 2010?

c++multithreadingvisual-studio-2010c++11

提问by J. Leeroy

I am new to c++ programming and I need to use the Thread class in my VS 2010 project. I've found this reference, but when I try the following:

我是 C++ 编程的新手,我需要在我的 VS 2010 项目中使用 Thread 类。我找到了这个参考,但是当我尝试以下操作时:

#include <thread>

VS 2010 obviously tells me 'Error: cannot open source file "thread"'. I understand that I need to "activate" c++11 standard somehow. I do not even know where to start.

VS 2010 显然告诉我“错误:无法打开源文件“线程””。我知道我需要以某种方式“激活”c++11 标准。我什至不知道从哪里开始。

So what should I do to use () c++11 standard in visual studio 2010?

那么我应该怎么做才能在visual studio 2010中使用() c++11标准呢?

回答by Mario

std::threadis obviously not in VS 2010. I think it was added with VS 2012, which is also supported by this question and answer. Is there any specific reason you're using 2010 rather than the latest version, 2013, which supports far more part of C++11?

std::thread显然不是在VS 2010中。我认为它是在VS 2012中添加的,这也是this question and answer的支持。您使用 2010 而非最新版本 2013 是否有任何具体原因,后者支持更多 C++11 部分?

Also to note: Contrary to GCC, MSVC doesn't have an "opt-in" for newer standards. It just supports them out of the box as far as implemented.

还要注意:与 GCC 不同,MSVC 没有“选择加入”新标准。就实现而言,它只是开箱即用地支持它们。

回答by Marius Bancila

The Visual C++ compiler is not fully C++11 compatible. C++11 features had been supported since Visual Studio 2010 and added incrementally. Not even the next version of Visual Studio will provide full C++11 compatibility. A matrix of C++11 features available in different versions of Visual Studio can be found here:

Visual C++ 编译器不完全兼容 C++11。自 Visual Studio 2010 起就支持 C++11 功能并逐步添加。即使是下一个版本的 Visual Studio 也不会提供完整的 C++11 兼容性。可以在此处找到不同版本的 Visual Studio 中可用的 C++11 功能矩阵:

回答by J. Leeroy

Here's what I've found by myself.

这是我自己发现的。

To "activate" c++11 in visual studio you need to set "Platform Toolset" in project->properties to v110 or above. So that's how visual studio will understand that it should use c++11 features.

要在 Visual Studio 中“激活”c++11,您需要将 project->properties 中的“Platform Toolset”设置为 v110 或更高版本。所以这就是 Visual Studio 将如何理解它应该使用 c++11 功能的方式。

BUT!

但!

The Visual C++ compiler is not fully C++11 compatible. C++11 features had been supported since Visual Studio 2010 and added incrementally. Not even the next version of Visual Studio will provide full C++11 compatibility.

Marius Bancila

Visual C++ 编译器不完全兼容 C++11。自 Visual Studio 2010 起就支持 C++11 功能并逐步添加。即使是下一个版本的 Visual Studio 也不会提供完整的 C++11 兼容性。

马里乌斯·班西拉

So it worked for <thread>(and <future>) in visual studio 2012.

所以它适用于<thread>(和<future>)在 Visual Studio 2012 中。

As I suggest it's impossible to set Platform Toolset above v100 in vs2010, so it's impossible to "activate" c++11 in vs2010.

正如我建议在 vs2010 中将平台工具集设置为高于 v100 是不可能的,所以在 vs2010 中不可能“激活”c++11。

Conclusion:to use c++11 standart features in visual studio you will need to use 2012 and higher version which supports Platform Toolset v110 and above.

结论:要在 Visual Studio 中使用 c++11 标准功能,您需要使用支持 Platform Toolset v110 及更高版本的 2012 及更高版本。

Correct me please if I'm wrong!

如果我错了,请纠正我!

回答by Juraj Blaho

C++11 is enabled by default, but there is not many features implemented in VS 2010. C++11 standard library is missing many headers in VS 2010. Here is a comparisonof a last few VS releases regarding the C++11 support.

默认启用 C++11,但在 VS 2010 中实现的功能并不多。C++11 标准库在 VS 2010 中缺少许多头文件。这是最近几个 VS 版本关于 C++11 的比较支持。