MFC中使用控制台輸出除錯資訊

2021-08-02 13:36:29 字數 557 閱讀 7184

mfc中使用控制台輸出除錯資訊

1.#include

2.在需要開啟控制台視窗的地方呼叫

allocconsole();//注意檢查返回值

3.在需要輸出除錯的時候呼叫_cprintf等函式

如_cprintf("i=%d\n", i);

4.關閉控制台的時候呼叫

freeconsole();

注意:上述方法在輸出中文時會出現亂碼,如果需要輸出中文,請使用下面的方法:

allocconsole();

freopen( "conout$","w",stdout);

printf("i的值為%d\n", i);

freeconsole();

報錯:error c4996: 'freopen': this function or variable may be unsafe. consider us

解決方案:

在專案屬性中找到「c/c++"——」預處理器」並在編輯視窗中新增編輯視窗中新增一句命令:_crt_secure_no_warnings

VC 6 0利用控制台輸出除錯資訊

方法一 windows為你提供了一系列的api來完成這個功能,例如 readconsole,writeconsole等,具體參見msdn。1。首先呼叫allocconsole函式來為你程序建立乙個console,該api是將當前程序attache到乙個新建立的console上。你還可以通過呼叫set...

在QT MFC中開啟控制台輸出除錯資訊

在qt和mfc程式設計過程中想要直接將除錯資訊通過printf輸出到控制台,如何實現?直接上 在qt 中開啟控制台視窗,首先include window.h 標頭檔案 define show console window ifdef show console window include endif...

MFC工程加入控制台除錯資訊輸出

本人將網上兩篇側重點不同的文章組合起來形成了下面這篇文章。實踐有效。taken from internet and used in internet 1.例項工程名為demo,在cdemodlg.h中加入 include define debug ifdef debug define debug f...