4

I have been following Bjarne Stroustrup's Book's C++ Programming and Principles 2nd Edition.

My problem is, in his book Bjarne uses some functions from the C++11 standard, which using the following code I discovered 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 machine with Win8.1 with platform toolset set to v12.0 or higher. I have VS 2010 and VS 2015 (just installed 2015 to see if it fixed the issue) installed on my machine as well.

None of this worked. Beyond the platform toolset being set to v12.0, I have not found any other solutions online. My friend that runs VS 2013 and 2015 on his Mac through parallels does not have this issue.

This thread has the same issue though the OP was using VS 2010: How to "activate" c++11 standard in visual studio 2010?

This thread demostrates that it may 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 point and have no idea how to fix it. Without this standard it makes following Bjarne's book nearly impossible.

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

EDIT / SOLUTION: So the main reason I made this post was while following the book above, I ran into an issue where using initializer-lists were not a recognized feature. According to other posts on this question and links provided, initializer-lists are clearly a feature of C++11 so after I used the above code I assumed I was not using C++11.

Below, are the steps I took to resolve this issue.

  1. First I uninstalled all 2010 redistributables including VS 2010 itself.
  2. Through Programs and Features, I ran VS 2013 uninstall wizard and selected 'repair'
  3. This resolved the issue I was getting about 'initializer-lists' not be recognized, however, there was another error that popped up that the book did not cover.

The error and solution I was getting ended up resulting from an out of date std_lib_facilities.h despite the fact I copied the link straight from the book .PDF

The error and solution I was getting can be found here: Simple Code Need Help - no instance of constructor matches argument list

PS: I have not reinstalled 2010 redistributables since I don't for see me having a need for them at the moment.

Community
  • 1
  • 1
Shawn Freeman
  • 76
  • 1
  • 6
  • Usually you do so using the appropriate compiler option, e.g. `--std=c++11` – πάντα ῥεῖ Apr 28 '15 at 14:02
  • 1
    this is because Visual studio 2013 does not have full C++11 support(e.g. constexpr is fully undefined, at least without some SP), so it only makes sense to not use C++11 macro. But on the other hand, VS2013 has full library support for C++11(it should) – Creris Apr 28 '15 at 14:03
  • That version check is pointless on VS, they haven't ever incremented the `__cplusplus` version. See [this](http://stackoverflow.com/q/14131454/241631). If you're using the latest platform toolset version you have installed, then you have all the features that that version of the compiler supports available to you. – Praetorian Apr 28 '15 at 14:07
  • 1
    @πάνταῥεῖ Visual studio does not support choosing a version of C++, you can turn on and off individual features though – Mgetz Apr 28 '15 at 14:24
  • I resolved my issue. I edited OP for future people having the same issue on what I did. – Shawn Freeman Apr 28 '15 at 22:18
  • Can you please add you edit as answer, this seems like a problem others could face and it should be put into an answer. This does not seem like an obvious duplicate of anything either. – Shafik Yaghmour Apr 29 '15 at 02:25

3 Answers3

1

Using C++11 in Visual Studio

You cannot "activate or change a certain C++ standard" in Visual Studio. If you want to use macros for conditional compilation you'll have to look up the features you're going to use and the Visual Studio Version supporting it.

If you know the desired version of MSVC you can use something along the lines of

#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 doesn't the macro equal 201103L if C++11 is (partially) supported?

Visual Studio doesn't fully support C++11: Supported C++11 features in VS2013.

Actually the standard says in a note about __cplusplus:

It is intended that future versions of this standard will replace the value of this macro with a greater value. Non-conforming compilers should use a value with at most five decimal digits.

I think the macro is not euqal to 201103L as long as Visual Studio doesn't fully conform to C++11 (if ever ;)).

I belive the macro says 199711L to indicate (almost full) C++98 conformance (although I there are C++98 features left which aren't included in VS).

Pixelchemist
  • 24,090
  • 7
  • 47
  • 71
  • By that logic, it shouldn't be set to `199711L` either because they don't fully support C++98, 2 phase name lookup being one of those unsupported things. – Praetorian Apr 28 '15 at 14:09
  • It shouldn't even have more than 5 digits if the macro itself was conformant to C++11. I think the meaning is more like "mostly conformant to C++98 but some important features of C++11 are missing" ;) – Pixelchemist Apr 28 '15 at 14:12
1

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

EDIT / SOLUTION: So the main reason I made this post was while following the book above, I ran into an issue where using initializer-lists were not a recognized feature. According to other posts on this question and links provided, initializer-lists are clearly a feature of C++11 so after I used 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 redistributables including VS 2010 itself. Through Programs and Features, I ran VS 2013 uninstall wizard and selected 'repair'. This resolved the issue I was getting about 'initializer-lists' not be recognized, however, there was another error that popped up that the book did not cover.

The error and solution I was getting ended up resulting from an out of date std_lib_facilities.h despite the fact I copied the link straight from the book .PDF

The error and solution I was getting can be found here: Simple Code Need Help - no instance of constructor matches argument list

PS: I have not reinstalled 2010 redistributables since I don't for see me having a need for them at the moment.

Shawn Freeman
  • 76
  • 1
  • 6
0

The issue for the thread you linked is that VS2010 doesn't support many C++11 features, such as std::thread (which is what that op needed).

VS2013 supports most C++11 features. You'll notice that if you make a project and #include <thread> it should work just fine for you.

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

RyanP
  • 1,898
  • 15
  • 20