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?

  • 0x0@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    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.