Preprocessor directive #error: 'DEBUG is defined'

Preprocessor directive #error: 'DEBUG is defined'

我将文件中的第一行设为:

#define DEBUG

在我的程序中,我将此变量用作:

    #region Preprocessor directives
    #if DEBUG
    #error DEBUG is defined
    #endif
    #endregion

编译时出现此错误:#error:'DEBUG is defined'

我是不是记错了什么?

正如我已经在评论中指出的那样,这正是 `#error' 预处理器指令的目的。 MSDN 上的描述说:

#error lets you generate an error from a specific location in your code.

在 MSDN 上查看此处:https://msdn.microsoft.com/en-us/library/x5hedts0.aspx

因此在您的情况下,您的指令告诉预处理器在设置 DEBUG 符号时显示错误 DEBUG is defined