print message to debug output window (VS)

本文介绍了一种在Visual Studio中调试程序的有效方法。通过使用特定格式输出信息,并调用OutputDebugString()函数,可以在输出窗口中查看并双击定位到源代码。此外,还提供了一个预处理指令示例,用于在编译时输出消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Some times we could want to print the debug messages to a window (console or windows) or a file, we debug our programms with these information. There's a better way to debug programm, print the message to output window if you use VS, and you can double click the message to locate the source codes. To achive this, you only need to:

1. sprintf the message to format as: __FILE__(__LINE__):message string

2. Invoke OutputDebugString() to print the message to ouput window.

Note: for c++, OutputDebugString() is for printing message into Output window; for dotnet, Debug.WriteLine() is for the same purpose.

else, you should want to print some messages to output window when compiling, yes you only need to:

1. format the message string

#define Stringize( L ) #L
#define MakeString( M, L ) M(L)
#define $Line MakeString(Stringize, __LINE__)
#define Reminder(_s_) __FILE__"("$Line"):"_s_

2. output

#pragma message(Reminder("aabbccddeeff"))


转自:http://blog.youkuaiyun.com/sunningPig

转载于:https://www.cnblogs.com/taoxu0903/archive/2011/04/21/2023810.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值