【轉(zhuǎn)】在vc下 output的打印
轉(zhuǎn)自:http://blog.chinaunix.net/u3/94302/showart_1891797.html
1,使用OutputDebugString在win32程序中可以使用函數(shù)OutputDebugString輸出調(diào)試信息。輸出的結(jié)果可以在vs的集成環(huán)境中看到,也可以使用工具DbgView.exe捕捉結(jié)果。函數(shù)的原形如下:OutputDebugStringThe OutputDebugString function sends a string to the debugger for display.void OutputDebugString(
LPCTSTR lpOutputString
);
Parameters
lpOutputString
[in] Pointer to the null-terminated string to be displayed.
Return Values
This function does not return a value
因為OutputDebugString的參數(shù)是字符串,而我們在實際使用過程中希望能像printf一樣支持變參。可以用下面的方法實現(xiàn)這個效果:
inline bool MyDbgStr(LPCSTR lpszFormat, ...)
{
va_list args;
int nBuf;
TCHAR szBuffer[512];
va_start(args, lpszFormat);
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer)*sizeof(TCHAR), lpszFormat, args);
Assert(nBuf > 0);
OutputDebugString(szBuffer);
va_end(args);
}
文章出處:http://www.diybl.com/course/3_program/c++/cppsl/200866/122894.html
1,使用OutputDebugString在win32程序中可以使用函數(shù)OutputDebugString輸出調(diào)試信息。輸出的結(jié)果可以在vs的集成環(huán)境中看到,也可以使用工具DbgView.exe捕捉結(jié)果。函數(shù)的原形如下:OutputDebugStringThe OutputDebugString function sends a string to the debugger for display.void OutputDebugString(
LPCTSTR lpOutputString
);
Parameters
lpOutputString
[in] Pointer to the null-terminated string to be displayed.
Return Values
This function does not return a value
因為OutputDebugString的參數(shù)是字符串,而我們在實際使用過程中希望能像printf一樣支持變參。可以用下面的方法實現(xiàn)這個效果:
inline bool MyDbgStr(LPCSTR lpszFormat, ...)
{
va_list args;
int nBuf;
TCHAR szBuffer[512];
va_start(args, lpszFormat);
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer)*sizeof(TCHAR), lpszFormat, args);
Assert(nBuf > 0);
OutputDebugString(szBuffer);
va_end(args);
}
文章出處:http://www.diybl.com/course/3_program/c++/cppsl/200866/122894.html
posted on 2009-04-15 16:42 shongbee2 閱讀(1157) 評論(0) 編輯 收藏 引用 所屬分類: windows相關(guān)