Reputation: 115
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?
Upvotes: 6
Views: 1707
Reputation: 2598
According to this question: Visual Studio 2012 __cplusplus and C++ 11 , provided by @paddy, this is a known bug with MSVC in that the version macro is set to C++98. You should compile with the /Zc:__cplusplus
switch to change the version macro to the correct value.
Upvotes: 3