VC调试时输出调试信息到Debug窗口

本文介绍了在MFC中使用的几种调试技巧,包括TRACE宏、afxDump对象和OutputDebugString函数的使用方法及其注意事项。

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

TRACE宏(afx.h, AfxTrace)
(TRACE将信息输出到afxDump对象,只在_DEBUG定义时输出,最多输出512个字符,格式化与printf类似)

afxDump对象(afx.h, CDumpContext)
(afxDump调用OutputDebugString把信息输出到Debug窗口,继承CObject的类可以重载Dump方法格式化此类的Dump信息,输出时把afxDump作为Dump方法的参数)

OutputDebugString(windows.h)
(TRACE, afxDump在使用MFC时使用,不使用MFC时可以用OutputDebugString,AfxOutputDebugString和OutputDebugString用法一样)

 

用法示例:

 

 
  1. int nCount = 9;

  2. CString strDesc("total");

  3.  
  4. TRACE("Count = %d, Description = %s\n", nCount, strDesc);

  5.  
  6.  
  7. #ifdef _DEBUG

  8. afxDump << "Count = " << nCount

  9. << ", Description = " << strDesc << "\n";

  10. #endif // _DEBUG

  11.  
  12.  
  13. #ifdef _DEBUG

  14. char strErr[512];

  15. sprintf(strErr, "Count = %d, Description = %s\n", nCount, strDesc);

  16. OutputDebugString()strErr;

  17. #endif // _DEBUG

转载于:https://my.oschina.net/u/1777508/blog/1858992

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值