也许:learncpp.com 更好,内容都来自这里,我简单的随手记一下

设置安全等级==4,设置警告是报错,设置语言标准为最新 命令行:/w44365

image-20240304221141494

image-20240304221200584

image-20240304221520231

以下程序应打印编译器当前配置使用的语言标准。您可以运行此程序来验证您的编译器是否使用您期望的语言标准。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>

const int numStandards = 7;
const long stdCode[numStandards] = { 199711L, 201103L, 201402L, 201703L, 202002L, 202302L, 202612L };
const char* stdName[numStandards] = { "Pre-C++11", "C++11", "C++14", "C++17", "C++20", "C++23", "C++26" };

long getCPPStandard()
{
// 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
return 1;
#else
// __cplusplus is the intended way to query the language standard code (as defined by the language standards)
return __cplusplus;
#endif
}

int main()
{
long standard{ getCPPStandard() };

if (standard == 1)
{
std::cout << "Error: Unable to determine your language standard. Sorry.\n";
return 0;
}

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;
}
}

std::cout << '\n';

return 0;
}