this post was submitted on 02 Jul 2023
8 points (100.0% liked)

No Stupid Questions (Developer Edition)

923 readers
1 users here now

This is a place where you can ask any programming / topic related to the instance questions you want!

For a more general version of this concept check out [email protected]

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

I just started learning c++. I installed visual studio with "Desktop Development with C++". CPlusPlus.com shows info for different c++ versions. How can I check which one I am using?

top 3 comments
sorted by: hot top controversial new old
[–] o11c 3 points 1 year ago

For what can be supported, see https://en.cppreference.com/w/cpp/compiler_support

Compilers generally have flags to select a version to conform to, and possibly for specific features. There are also several macros you can check. But beware of bugs and lies.

[–] jamesb5 3 points 1 year ago

Check what version of visual studio you’re using. That will have support for certain levels of c++.

If you have 2019 or 2022 installed with the latest updates, you should have complete converse of c++20 and all older standards.

https://devblogs.microsoft.com/cppblog/msvcs-stl-completes-stdc20/

[–] 0x0 2 points 1 year ago

See this for reference.

Here's a snippet:

#if defined(__cplusplus) && __cplusplus >= 201703L
    std::cout << "compiler supports C++17" << std::endl;
#elif defined(__cplusplus) && __cplusplus >= 201402L
    std::cout << "compiler supports C++14" << std::endl;
#elif defined(__cplusplus) && __cplusplus >= 201103L
    std::cout << "compiler supports C++11" << std::endl;
#elif defined(__cplusplus) && __cplusplus >= 199711L
    std::cout << "compiler supports C++98" << std::endl;
#else
    std::cout << "compiler supports C++, standard unknown" << std::endl;
#endif

To specify at compile-time, use g++ -std=c++17 for instance.