共用方式為


編譯器警告 (層級 1) C4067

未預期的語彙基元,接著前置處理器指示詞 - 必須是新行

備註

編譯程式會在預處理器指示詞之後找到並忽略額外的字元。 這可能會由任何非預期的字元所造成,但常見的原因是指示詞之後的流浪分號。 批注不會造成這個警告。 /Za 編譯程式選項會針對比預設設定更多的預處理器指示詞啟用這個警告。

範例

下列範例會產生 C4067:

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