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用法一样)
用法示例:
int nCount = 9;
CString strDesc("total");
TRACE("Count = %d, Description = %s\n", nCount, strDesc);
#ifdef _DEBUG
afxDump << "Count = " << nCount
<< ", Description = " << strDesc << "\n";
#endif // _DEBUG
#ifdef _DEBUG
char strErr[512];
sprintf(strErr, "Count = %d, Description = %s\n", nCount, strDesc);
OutputDebugString()strErr;
#endif // _DEBUG