標(biāo)題: 純C++中怎么輸出調(diào)試信息 [打印本頁]

作者: bibi    時(shí)間: 2015-4-18 20:54
標(biāo)題: 純C++中怎么輸出調(diào)試信息
在MFC程序中有TRACE等一系列的宏可以輸出調(diào)試信息, 但是其他的地方不能用了, 下面這個(gè)小程序測試了怎么輸出調(diào)試信息,

// Test_ErrorCode.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//

#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.torrancerestoration.com/bbs/) Powered by Discuz! X3.1