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

2021-06-13 05:36:34 字數 938 閱讀 6505

方法一:

windows為你提供了一系列的api來完成這個功能,例如:readconsole,writeconsole等,具體參見msdn。   

1。首先呼叫allocconsole函式來為你程序建立乙個console,該api是將當前程序attache到乙個新建立的console上。你還可以通過呼叫setconsoletitle(tstrname);來設定console的title.   

2。使用writeconsoleoutput來將資訊輸出到console上;在輸出之前,先要得到console的handle,這通過getstdhandle(std_output_handle)來得到,然後將資訊組織成console的格式,然後輸出。   

3。關閉console。當不需要這個console的時候,呼叫freeconsole來將當前程序從console中detach中。   

第二種方案: 

在   project   |   setting...中,選項   post-builder   step   裡新建command,   輸入:     

editbin   /subsystem:console   $(outdir)\filename.exe     

(其中   filename   為可執行檔名)     

則可以使用   printf   或者   std::cout   在控制台中輸出了。例如你的可執行檔名為   helloworld.exe,則你新建的   command   就為     

editbin     /subsystem:console     $(outdir)\helloworld.exe     

第三種方案:

就用trace,然後編譯debug的工程,直接執行你的可執行檔案,可以用dbgview來獲得輸出。

第四種方案:

個人用了第三種,覺得挺好的,不過需要在上面下個dbgview。

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

mfc中使用控制台輸出除錯資訊 1.include 2.在需要開啟控制台視窗的地方呼叫 allocconsole 注意檢查返回值 3.在需要輸出除錯的時候呼叫 cprintf等函式 如 cprintf i d n i 4.關閉控制台的時候呼叫 freeconsole 注意 上述方法在輸出中文時會出現...

在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...