随感而发

杂七杂八

统计

留言簿(13)

阅读排行榜

评论排行榜

【转】在vc下 output的打印

转自:http://blog.chinaunix.net/u3/94302/showart_1891797.html
1,使用OutputDebugString在win32程序中可以使用函数OutputDebugString输出调试信息。输出的结果可以在vs的集成环境中看到,也可以使用工具DbgView.exe捕捉结果。函数的原形如下: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的参数是字符串,而我们在实际使用过程中希望能像printf一样支持变参。可以用下面的方法实现这个效果:
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 阅读(1116) 评论(0)  编辑 收藏 引用 所属分类: windows相关


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理