我剛開始使用 QT6(以及一般的 QT)。
我試過做simpe cin/cout操作,已經很麻煩了。cin 不讀取一行,getline 也不讀取。
這是我的代碼:
#include <QCoreApplication>
#include <iostream>
#include <string>
using namespace std;
void do_something()
{
string name = "";
cout << "Enter your name: \n";
cin >> name;
cout << "Hello " << name << "\n";
return;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
do_something();
return a.exec();
}
“輸入你的名字:”這一行寫了,換行符沒有!?然后無論我在控制臺中輸入什么,都不會對cin做任何事情,而且程式是,因為它似乎卡在cin中。
如果我在第二次 cout 中使用“endl”代替“\n”作為“\n”,則會發生以下情況。Cin 完全被忽略,“Hello”也被列印出來。
uj5u.com熱心網友回復:
解決方案是,如評論中所寫:
在終端中運行程式,而不是在 QT Creator 的輸出終端中運行。在輸出終端中,您不能輸入任何輸入。
重繪 緩沖區,因為文本位于緩沖區中,直到發生 endl 或重繪 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/401224.html
上一篇:僅選擇元素或導航選單中的文本
