How to change the C ++ standard in Visual Studio 2013

I am following Bjarne Stroustrup Book C ++ Programming and Principles 2nd Edition .

My problem is that in his book, Bjarne uses some features from the C ++ 11 standard which, using the following code, I found I was using C ++ 98.

if (__cplusplus == 201103L) std::cout << "C++11\n";
else if (__cplusplus == 199711L) std::cout << "C++98\n";
else std::cout << "pre-standard C++\n";

      

When I discovered this, I was using VS 2013 Ultimate on a Win8.1 machine with the platform toolbox installed to v12.0 or higher. I have VS 2010 and VS 2015 (2015 just installed to check if the problem is fixed) installed on my computer as well.

None of this worked. Apart from the platform toolset installed at v12.0, I have not found any other solutions on the internet. A friend of mine who is running VS 2013 and 2015 on his Mac via parallels doesn't have this problem.

This thread has the same problem, although the OP is using VS 2010: How do I activate "C ++ 11 in Visual Studio 2010?"

This thread demonstrates that it might be a Microsoft issue, but still no solution: https://connect.microsoft.com/VisualStudio/feedback/details/763051/a-value-of-predefined-macro-cplusplus-is- still-199711l

I am completely lost at this stage and have no idea how to fix this. Without this standard, he makes Bjarne's next book nearly impossible.

How do I change or update my C ++ standard?!?!

EDIT / SOLUTION . So the main reason I posted this article was to follow the book above, I ran into an issue where using initializer lists was not a recognized feature. According to other posts on the subject and the links provided, init lists are clearly a C ++ 11 hallmark, so after I used the code above, I assumed I was not using C ++ 11.

Below are the steps I took to resolve this issue.

  • I first uninstalled all the 2010 2010 redistributables, including VS 2010 itself.
  • Through programs and functions, I launched the Windows 2013 uninstall wizard and selected "repair"
  • This resolved the problem I was getting about "initializer lists" not being recognized, but there was another error that came up because the book was not being distributed.

The error and solution I was getting was std_lib_facilities.h being deprecated even though I copied the link directly from the .PDF book

The error and solution I was getting can be found here: Simple Code Need Help - No Constructor Instance Matches Argument List

PS: I haven't reinstalled the 2010 redistributable files as I don't see that I have a need for them at the moment.

+3


source to share


3 answers


Using C ++ 11 in Visual Studio

You cannot "activate or change a specific C ++ standard" in Visual Studio. If you want to use macros for conditional compilation, you have to look for the functions you intend to use and the version of Visual Studio that supports it.

If you know the MSVC version you want you can use something along the lines

#if _MSC_VER >= 1800
// ...
#endif

      

VS2010 has #define _MSC_VER 1600

, VS2012 has #define _MSC_VER 1700

, and VS2013 has #define _MSC_VER 1800

afaik.

Why is the macro not equal 201103L

if C ++ 11 is supported?



Visual Studio does not fully support C ++ 11: Supported C ++ 11 features in VS2013 .

In fact, the standard says in a note about __cplusplus

:

It is anticipated that future versions of this standard will replace the meaning of this macro with a larger meaning. Non-compliant compilers should use a value of no more than five decimal digits.

I think the macro is not euqal 201103L

until Visual Studio is fully C ++ 11 compliant (if ever;)).

I believe the macro says 199711L

to indicate (almost complete) C ++ 98 conformance (although I have C ++ 98 features that are not included in VS).

0


source


The problem for a linked thread is that VS2010 does not support many C ++ 11 features like std :: thread (which is what the operator needs).

VS2013 supports most of the C ++ 11 features. You will notice that if you create a project and #include <thread>

it should work just fine for you.



To see what C ++ 11 features your compiler supports, check out this: C ++ 11 Core Features Table

0


source


I am adding this answer per request. This answer can also be found in the OP as an edit.

EDIT / SOLUTION . So the main reason I posted this article was to follow the book above, I ran into an issue where using initializer lists was not a recognized feature. According to other posts on the subject and the links provided, initializer lists are clearly C ++ 11 hallmarks, so after using the above code, I assumed I was not using C ++ 11.

Below are the steps I took to resolve this issue.

First, I uninstalled all 2010 2010 redistributables, including VS 2010 itself. Through programs and functions, I launched the Windows 2013 uninstall wizard and selected "repair". This solved the problem I was getting for the "initializer lists" not to be recognized, however there was another error that occurred due to the book not being distributed.

The error and solution I was getting was std_lib_facilities.h being deprecated even though I copied the link directly from the .PDF book

The error and solution I was getting can be found here: Simple Code Need Help - No Constructor Instance Matches Argument List

PS: I haven't reinstalled the 2010 redistributable files as I don't see that I have a need for them at the moment.

0


source







All Articles