問題描述
我正在使用 Qt4 和 C++ 來制作一些計(jì)算機(jī)圖形程序.我需要能夠在運(yùn)行時(shí)在我的控制臺(tái)中打印一些變量,而不是調(diào)試,但是即使我添加了庫,cout
似乎也不起作用.有沒有辦法做到這一點(diǎn)?
I'm using Qt4 and C++ for making some programs in computer graphics. I need to be able to print some variables in my console at run-time, not debugging, but cout
doesn't seem to work even if I add the libraries. Is there a way to do this?
推薦答案
如果打印到 stderr
足夠好,您可以使用以下最初用于調(diào)試的流:
If it is good enough to print to stderr
, you can use the following streams originally intended for debugging:
盡管如評(píng)論中所指出的,請(qǐng)記住,如果定義了 QT_NO_DEBUG_OUTPUT
,則會(huì)刪除 qDebug 消息
Though as pointed out in the comments, bear in mind qDebug messages are removed if QT_NO_DEBUG_OUTPUT
is defined
如果你需要標(biāo)準(zhǔn)輸出,你可以嘗試這樣的事情(正如凱爾斯特蘭德指出的那樣):
If you need stdout you could try something like this (as Kyle Strand has pointed out):
然后您可以按如下方式調(diào)用:
You could then call as follows:
這篇關(guān)于使用Qt時(shí)如何打印到控制臺(tái)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!