找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 3201|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

純C++中怎么輸出調(diào)試信息

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:77367 發(fā)表于 2015-4-18 20:54 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
在MFC程序中有TRACE等一系列的宏可以輸出調(diào)試信息, 但是其他的地方不能用了, 下面這個(gè)小程序測(cè)試了怎么輸出調(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;
}




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表