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
int nCount = 9;
對象
CString strDesc("total");
繼承
TRACE("Count = %d, Description = %s\n", nCount, strDesc);
ip
#ifdef _DEBUG
io
afxDump << "Count = " << nCount
class
<< ", Description = " << strDesc << "\n";
bug
#endif // _DEBUG
方法
#ifdef _DEBUG
di
char strErr[512];
sprintf(strErr, "Count = %d, Description = %s\n", nCount, strDesc);
OutputDebugString()strErr;
#endif // _DEBUG