2

I'm trying to get the C++ version I'm using, which I assumed was an easy task as developers need the version number to see which functionality is available (or is that a wrong assumption)? I tried the advised method from here:

auto someversion = __cplusplus;
std::cout << someversion;

which shows:

199711

According to the linked answer that means im using C++98. Is this correct or is there another method to get the right version number?

I also tried running the command:

g++ --version

But the command did not run (Command "g++" is not valid.). How do I find out which C++ version I am running?

edit: context

So how does one see which functionality is available or do you just need to try and find out? I'm trying async but when i copy the example my syntax is not valid, thats when I checked for the version number to see if the syntax from the example was useable with my setup. (the example : )

Sven van den Boogaart
  • 11,833
  • 21
  • 86
  • 169
  • 1
    The C++ standard version is a "compiler thing", not a runtime value. Also a compiler may not support all features of a given standard, so such a value wouldn't be able to inform you of everything – UnholySheep Oct 18 '17 at 13:30
  • 2
    You're never really using a specific version because none of them are fully implemented (yet). In the case of other compilers, they remain partially implemented for quite a while. To be more reliable, *features* need to be checked for, not versions. – chris Oct 18 '17 at 13:30
  • 1
    Visual C++ and g++ are two different compilers. Unclear what the question is. – Ron Oct 18 '17 at 13:31
  • 1
    `g++` is the [GCC (GNU Compiler Collection)](https://gcc.gnu.org/) frontend or driver program for C++, which doesn't come with Visual Studio. The Microsoft Visual C++ frontend program is called `cl`. – Some programmer dude Oct 18 '17 at 13:31
  • 3
    it's complicated with Visual C++ because they don't yet implement all of C++98 (that's still in C++17) so they refuse to update that until they do. – Mgetz Oct 18 '17 at 13:34
  • Thanks for all the comments, so how does one see which functionality is available or do you just need to try and find out? I'm trying async but when i copy the example my syntax is not valid, thats when i checked for the version number. (the example : https://solarianprogrammer.com/2012/10/17/cpp-11-async-tutorial/ ) – Sven van den Boogaart Oct 18 '17 at 13:35
  • @SvenvandenBoogaart there is a compiler flag you'll need to [enable for coroutines](https://blogs.msdn.microsoft.com/vcblog/2015/04/29/more-about-resumable-functions-in-c/) – Mgetz Oct 18 '17 at 13:37
  • @Mgetz nothing in the link he provided uses coroutines, it's just plain C++11 std::async which is supported just fine in VS2017 – PeterT Oct 18 '17 at 13:41
  • @SvenvandenBoogaart, There are nice [tables](http://en.cppreference.com/w/cpp/compiler_support) that work well if you know which compilers you plan to support/use. – chris Oct 18 '17 at 13:42
  • @SvenvandenBoogaart> I'd say usually it's the other way around: first you define your needs, and then choose a tool that matches those needs. Only if you then find none exists you might lower your expectations. (as for compilers you'll find most support different dialects of the language and you need to specify which you want to use) – spectras Oct 18 '17 at 13:51
  • @Ron I tried to implement some examples (see comment above) but my syntax was not valid, i tried finding out if i was using a c++ version which supports the syntax i was trying but i could not find the vesion. comments showed version of c++ dosnt mather. I still dont know how to find out how i can check if i can use some syntax like "std::future result( std::async(called_from_async));" from the example. – Sven van den Boogaart Oct 18 '17 at 13:53
  • @SvenvandenBoogaart> you need to configure your compiler. I don't know VC++, but for instance with gcc you tell it when you invoke it which version of the language you want. Say, `gcc -std=c++11` or `gcc -std=c++14` or ... if you don't, your compiler will pick one for you. – spectras Oct 18 '17 at 13:56
  • VS2017 in particular has a setting `/std:c++latest` which enables as much support as it has for new features. – Bo Persson Oct 18 '17 at 13:57

1 Answers1

1

Run:

cl

The output should be something like this:

Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x86

Then, see Visual C++ Language Conformance to check exactly which features are supported by your compiler.

Daniel Trugman
  • 8,186
  • 20
  • 41