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

相關文章
相關標籤/搜索