#pragma message()怎么用,看了一些参考还是不太明白-------来个“完整”的例子看下

tudou614 2005-05-09 12:51:45
RT
...全文
367 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tudou614 2005-05-09
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

int main()
{
#ifdef _DEBUG_EVENT
#if _M_IX86 == 500
#pragma message( "Pentium processor build" )
#endif



cout<<"宏_M_IX86"<<_M_IX86<<endl;
#endif

cin.get();
return 0;
}

这样不是还是不行??

或者上面的 _DEBUG_EVENT 换成 _DEBUG

道理上能讲地通啊,实践起来怎么就不行呢??我真菜,谁给个例子程序看下??
tudou614 2005-05-09
  • 打赏
  • 举报
回复
它是通过给预处理器下命令来实现的的,如果我定义了_M_IX86这个宏,就报告一条"Pentium processor build"消息,但是,这个消息到底需要在VC环境中如何设置才能才能使上面的小程序显示
"Pentium processor build"这个消息出来??

tudou614 2005-05-09
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;
int main()
{
#if _M_IX86 == 500
#pragma message( "Pentium processor build" )
#endif

cin.get();
return 0;
}
比如说上面的程序代码,我即没有在CONSOLE的DOS BOX中看到它显示出来,也没有看到它在BUILD或者是DEBUG窗口中显示出来,请问如何才能让这个"Pentium processor build" 显示出来??
healer_kx 2005-05-09
  • 打赏
  • 举报
回复
#pragma message( "Pentium processor build" )

这就是语法...
guyaguya 2005-05-09
  • 打赏
  • 举报
回复
#pragma message( messagestring )

Sends a string literal to the standard output without terminating the compilation. A typical use of the message pragma is to display informational messages at compile time.

The following code fragment uses the message pragma to display a message during compilation:

#if _M_IX86 == 500
#pragma message( "Pentium processor build" )
#endif

The messagestring parameter can be a macro that expands to a string literal, and you can concatenate such macros with string literals in any combination. For example, the following statements display the name of the file being compiled and the date and time when the file was last modified:

#pragma message( "Compiling " __FILE__ )
#pragma message( "Last modified on " __TIMESTAMP__ )

yhb7805 2005-05-09
  • 打赏
  • 举报
回复
简单说就是在编译的时候输出(警告)信息。
除了象楼上的,还有
#ifdef _MY_DEFINE_
#pragma message("已经被定义_MY_DEFINE_")
#endif
chunhai12 2005-05-09
  • 打赏
  • 举报
回复
【MSDN】
The following code fragment uses the message pragma to display a message during compilation:

#if _M_IX86 == 500
#pragma message( "Pentium processor build" )
#endif

64,654

社区成员

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

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