longgetCPPStandard() { // Visual Studio is non-conforming in support for __cplusplus (unless you set a specific compiler flag, which you probably haven't) // In Visual Studio 2015 or newer we can use _MSVC_LANG instead // See https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ #if defined (_MSVC_LANG) return _MSVC_LANG; #elif defined (_MSC_VER) // If we're using an older version of Visual Studio, bail out return1; #else // __cplusplus is the intended way to query the language standard code (as defined by the language standards) return __cplusplus; #endif }
intmain() { long standard{ getCPPStandard() };
if (standard == 1) { std::cout << "Error: Unable to determine your language standard. Sorry.\n"; return0; }
std::cout << "Your compiler is using language standard: "; for (int i = 0; i < numStandards; ++i) { if (standard <= stdCode[i]) { std::cout << stdName[i]; // If the reported version is between two standard codes, this must be a preview / experimental support if (standard < stdCode[i]) std::cout << " (preview)"; break; } }