lundi 19 octobre 2020

Know which version of c++ is running on Visual Studio

I'm trying to set up c++11 to my project on visual studio, and to find out which version the compiler used by default I used the following code:

#include <iostream>

int main(){
        #if __cplusplus==201402L
        std::cout << "C++14" << std::endl;
        #elif __cplusplus==201103L
        std::cout << "C++11" << std::endl;
        #elif __cplusplus==199711L
        std::cout << "C++" << std::endl;
        #elif __cplusplus==201703L
        std::cout << "C++17" << std::endl;
        #elif __cplusplus==1
        std::cout << "C+" << std::endl;
        #endif

        int* i = nullptr;

        return 0;
}

Having output c++ (98) I tried to force the compiler to use c++11 via the CMakeLists like this:

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

The output was always C ++ (98), so I added

int* i = nullptr;

and amazingly the output remains c++ (98) but the application works without problems. How is this "anomaly" explained and how do I know / decide which standard to use?

Aucun commentaire:

Enregistrer un commentaire