I am trying to check the version of c++ i have with the following code.
if (__cplusplus == 201703L) std::cout << "C++17\n";
else if (__cplusplus == 201402L) std::cout << "C++14\n";
else if (__cplusplus == 201103L) std::cout << "C++11\n";
else if (__cplusplus == 199711L) std::cout << "C++98\n";
else std::cout << "pre-standard C++\n";
the output is C++98 version , but i am definitely able to use c++11 features so i think i am not getting the correct version from the code.
How can i check which version of c++ i am using ?
To check if Visual C++ redistributables are installed, open Add and Remove Programs and look for the Microsoft Visual C++ Redistributable. If installed, you see "Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.22. 27821".
In versions of Visual Studio 2019 before version 16.11, /std:c++latest is required to enable all the compiler and standard library features of C++20. For a list of supported language and library features, see What's New for C++ in Visual Studio.
Visual Studio 2017 version 15.3/std:c++17 enables the set of C++17 features implemented by the compiler.
Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion.
Easier way to check it than writing a program is under Project (right-click your project name in solution explorer) > Properties > C/C++ > Language > C++ Language Standard
And you can also change it there.
I know it thanks to this answer.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With