12

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:

#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.

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

5
  • 6
    <thread> was added in VS2012 and further expanded in VS2013. so, if you want to enable <thread>, you're either gonna have to upgrade your IDE or use another compiler. Commented Nov 8, 2013 at 11:00
  • 1
    Does it not set off alarm bells that you want 2011 standard support in a produce named 2010? Commented Nov 8, 2013 at 11:09
  • 1
    @DavidHeffernan, that's not very relevant. OP, I think with some hacking around you can set a custom build option for your project and use GCC on mingw or something.
    – Codecat
    Commented Nov 8, 2013 at 11:13
  • 1
    @AngeloGeels Using mingw somehow is relevant?! Commented Nov 8, 2013 at 11:18
  • 2
    Since GCC supports C++11 (almost?) completely, yes.
    – Codecat
    Commented Nov 8, 2013 at 13:15

5 Answers 5

10

std::thread is 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?

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.

6
  • 1
    VS 2012 and 2013 tend to show its instabilities.. Also, VS 2010 has macros, while the newer versions do not.
    – Codecat
    Commented Nov 8, 2013 at 11:08
  • 1
    Macros? Also never had any issue with 2012/2013 so far (besides broken std::regex in 2012).
    – Mario
    Commented Nov 8, 2013 at 11:09
  • 2
    2012/2013 tend to use much more resources as compared to 2010 when working with huge projects, which makes it required to restart the IDE every couple hours. (2010 also has this, but much less) Macros: msdn.microsoft.com/en-us/library/b4c73967%28v=vs.100%29.aspx
    – Codecat
    Commented Nov 8, 2013 at 11:10
  • 1
    Haven't heard about such issues and never really touched IDE macros. But besides that, if you worry about the newer IDE, you can still install a newer version parallel to the existing Installation (either full IDE or just the platform SDK) and then select this as a different compiler from the project settings (introduced with MSVC 2010 I think).
    – Mario
    Commented Nov 8, 2013 at 11:18
  • I'm using 2010 because of the specific program which generates source code and solution files for vs2010. There is an option to generate for 2012 in that programm, but it I already had 2010 installed on my machine. So did not try to use 2012 because it was unnecessary until now (need thread Class). Right now I'm getting and installing 2012 and 2013 to check your answer.
    – J. Leeroy
    Commented Nov 8, 2013 at 12:44
7

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:

3

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 comparison of a last few VS releases regarding the C++11 support.

3

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.

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

So it worked for <thread> (and <future>) in 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.

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.

Correct me please if I'm wrong!

0

d= (◕‿↼ ) C++11 is enabled by default, But unfortunately, not even "Visual Studio 2017" is fully C++11 compliant.

(I got here while building Boost, which's build section only mentions their need for C++11 compliant compiler, and NOT with what MSVC version they tested Boost.)

Microsoft says:

"Support for C11 and C17 standards is available in Visual Studio 2019 version 16.8 and later"

But I didn't test their claim yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.