How to determine the version of the C++ standard used by the compiler?
By my knowledge there is no overall way to do this. If you look at the headers of cross platform/multiple compiler supporting libraries you'll always find a lot of defines that use compiler specific constructs to determine such things:
/*Define Microsoft Visual C++ .NET (32-bit) compiler */
#if (defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER >= 1300)
...
#endif
/*Define Borland 5.0 C++ (16-bit) compiler */
#if defined(__BORLANDC__) && !defined(__WIN32__)
...
#endif
You probably will have to do such defines yourself for all compilers you use.
How to check which version of C my compiler is using?
You can look at the __STDC_VERSION__
macro, which hast the format YYYYMM and from that deduce whether you run C89, C99, C11 or C18.
See also What is the __STDC_VERSION__ value for C11?
How to determine what C++ standard is the default for a C++ compiler?
What about compiling and executing the following trivial program ?
#include <iostream>
int main()
{ std::cout << __cplusplus << std::endl; }
The value printed should say the version used:
- 199711 for C++98,
- 201103 for C++11
- 201402 for C++14
- 201703 for C++17
If you compile omitting the -std=c++xx
flag, you should be able to detect the default version of language used.
How can I figure out what is the default standard used by my C compiler GCC ?
When in doubt, consult the documentation. The gcc man-page makes it clear that -std=gnu89
is the default for C code, and -std=gnu++98
is the default for C++ code. The meaning of these options is described both in the man page and, in much more detail, in the extensive info documentation that is also available online.
These defaults for these flags have changed before and will change again, so it is best to check before assuming specific values.
UPDATE
The defaults have changed over the years. As of GCC 8.3.0, released in February 2019, the default standard for C is -std=gnu11
, and -std=gnu++14
for C++. To be sure, look at the documentation of the compiler version you are actually using.
How to check c++ version in microsoft visual studio 2017
From https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
You need to compile with the
/Zc:__cplusplus
switch to see the updated value of the__cplusplus
macro.
Note that this was added in MSVC 2017 (version 15.7 Preview 3), it's not available in older versions.
Related Topics
What Happens When I Print an Uninitialized Variable in C++
What Happens to a Detached Thread When Main() Exits
Reading and Writing Binary File
Cmake Error At Cmakelists.Txt:30 (Project): No Cmake_C_Compiler Could Be Found
In C++ Books, Array Bound Must Be Constant Expression, But Why the Following Code Works
How to Pass a Multidimensional Array to a Function in C and C++
Can Modern X86 Hardware Not Store a Single Byte to Memory
Remove Spaces from Std::String in C++
Two Phase Lookup - Explanation Needed
What Is the Lifetime of the Result of Std::String::C_Str()
How to Redirect Cin and Cout to Files
How to Make a Http Request With C++