编译器警告(等级 1)C4067

预处理器指令后有意外标记 - 应输入换行符

备注

编译器找到并忽略了预处理器指令之后的额外字符。 这可由任何意外字符引起,尽管常见原因是指令后面的杂乱分号。 注释不会导致此警告。 /Za 编译器选项为预处理器指令启用此警告,而不是默认设置。

示例

// C4067a.cpp
// compile with: cl /EHsc /DX /W1 /Za C4067a.cpp
#include <iostream>
#include <string> s     // C4067
#if defined(X);         // C4067
std::string s{"X is defined"};
#else
std::string s{"X is not defined"};
#endif;                 // C4067 only under /Za
int main()
{
    std::cout << s << std::endl;
}

若要解决此警告,请删除流浪字符,或将它们移动到注释块中。 可以通过删除 /Za 编译器选项来禁用某些 C4067 警告。

// C4067b.cpp
// compile with: cl /EHsc /DX /W1 C4067b.cpp
#include <iostream>
#include <string>
#if defined(X)
std::string s{"X is defined"};
#else
std::string s{"X is not defined"};
#endif
int main()
{
    std::cout << s << std::endl;
}