#error

guoxianyu521 2009-08-12 08:43:33
#error 麻烦给我个“实例”,及何时使用?
...全文
101 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
满衣兄 2009-08-12
  • 打赏
  • 举报
回复
例子:
#if !defined(__cplusplus1) 
#error C++ compiler required.
#endif

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

编译的时候就会报错:C++ compiler required
输出如下:
1>------ 已启动全部重新生成: 项目: asfsafd, 配置: Debug Win32 ------
1>Deleting intermediate and output files for project 'asfsafd', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>asfsafd.cpp
1>e:\test\asfsafd\asfsafd\asfsafd.cpp(7) : fatal error C1189: #error : C++ compiler required. 1>Generating Code...
1>Build log was saved at "file://e:\test\asfsafd\asfsafd\Debug\BuildLog.htm"
1>asfsafd - 1 error(s), 0 warning(s)
========== 全部重新生成: 0 已成功, 1 已失败, 0 已跳过 ==========
guoxianyu521 2009-08-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sttony 的回复:]
#if !defined(__cplusplus)
#error C++ compiler required.
#endif

如果没有定义c++宏,编译的时候输出错误信息, C++ compiler required.

注意是编译的时候,出现在编译的shell输出上
[/Quote]

我把代码copy到vc上也没有啥反应呀??
我想要一个可以直接在vc上运行且有反应的代码。嘿嘿,有劳大家了!
sttony 2009-08-12
  • 打赏
  • 举报
回复
#if !defined(__cplusplus)
#error C++ compiler required.
#endif

如果没有定义c++宏,编译的时候输出错误信息, C++ compiler required.

注意是编译的时候,出现在编译的shell输出上
guoxianyu521 2009-08-12
  • 打赏
  • 举报
回复
想起来了,是CSDN上的原话。


麻烦前辈们,给我个“实例”。我不会用呀!!
飞天御剑流 2009-08-12
  • 打赏
  • 举报
回复
#error语法如下:

#error 信息

例如:

#error This software requires the UNIX OS.

这条指令主要给出错误信息,上面的这个例子就是输出This software requires the UNIX OS.
guoxianyu521 2009-08-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lingyin55 的回复:]
The #error Directive 

Error directives produce compiler-time error messages.


#error token-string


Remarks
The error messages include the argument token-string and are currently not subject to macro expansion. These directives are most useful for detecting programmer inconsistencies and violation of constraints during preprocessing. The following example demonstrates error processing during preprocessing:

  Copy Code
#if !defined(__cplusplus)
#error C++ compiler required.
#endif


When #error directives are encountered, compilation terminates.

[/Quote]



请问前辈,这些东西是在哪找到的?
asksgp 2009-08-12
  • 打赏
  • 举报
回复
#error 错误宏,具体意思的结合前后代码
lingyin55 2009-08-12
  • 打赏
  • 举报
回复
The #error Directive

Error directives produce compiler-time error messages.


#error token-string


Remarks
The error messages include the argument token-string and are currently not subject to macro expansion. These directives are most useful for detecting programmer inconsistencies and violation of constraints during preprocessing. The following example demonstrates error processing during preprocessing:

Copy Code
#if !defined(__cplusplus)
#error C++ compiler required.
#endif


When #error directives are encountered, compilation terminates.

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧