VSC - IntelliSense 将布尔运算符标记为错误

VSC - IntelliSense marks boolean operator as errors

IntelliSense 错误地将布尔运算符(andor 等)标记为错误。这是一个例子:

这是我的 c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}

有人知道为什么会这样吗?

对于 Visual C++,您似乎需要添加 #include <iso646.h>.

C++ specifies bitand as an alternative spelling for &. In C, the alternative spelling is provided as a macro in the <iso646.h> header. In C++, the alternative spelling is a keyword; use of <iso646.h> or the C++ equivalent is deprecated. In Microsoft C++, the /permissive- or /Za compiler option is required to enable the alternative spelling.

包含头文件后,不再报错:

Wikipedia also cites:

Some compilers, such as Microsoft Visual C++ have, at least in the past, required the header to be included in order to use these identifiers.