标题: 纯C++中怎么输出调试信息 [打印本页]

作者: bibi    时间: 2015-4-18 20:54
标题: 纯C++中怎么输出调试信息
在MFC程序中有TRACE等一系列的宏可以输出调试信息, 但是其他的地方不能用了, 下面这个小程序测试了怎么输出调试信息,

// Test_ErrorCode.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>

void __cdecl odprintf(const char* fmt, ...)
{
        char buf[4096], *p = buf;
        va_list args;

        va_start(args, fmt);
        p += vsnprintf_s(p, sizeof(buf), _TRUNCATE, fmt, args);
        va_end(args);

        while ( p > buf  &&  isspace(p[-1]) )
                *--p = '\0';
        *p++ = '\r';
        *p++ = '\n';
        *p   = '\0';

        OutputDebugStringA(buf);        //OutputDebugString
}


int _tmain(int argc, _TCHAR* argv[])
{
        odprintf("Testing...");
        HANDLE hFile = CreateFile(_T("c://a.txt"), 0, 0, NULL, OPEN_EXISTING,0,NULL);
        odprintf("Retrieve last error code = %ld", ::GetLastError());

        return 0;
}









欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1