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

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用法同样)windows

 

用法示例:code

 

 
  1. int nCount = 9;对象

  2. CString strDesc("total");继承

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

  5.  
  6.  
  7. #ifdef _DEBUGio

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

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

  10. #endif // _DEBUG方法

  11.  
  12.  
  13. #ifdef _DEBUGdi

  14. char strErr[512];

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

  16. OutputDebugString()strErr;

  17. #endif // _DEBUG

相关文章
相关标签/搜索