I am just starting with QT6 (and with QT in general).
I have tried to do simpe cin/cout operations and it's already troublesome. Somehow cin does not read a line, nor does getline.
Here is my code:
#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();
}
The line "Enter your name: " get's written, the newline character does not!? Then whatever i type in the console, does not do anything to cin, and the program is, as it seems stuck in cin.
If instead of "\n" i use "endl" for the "\n" at the second cout, the following happens. Cin is completely getting ignored and the "Hello" also gets printed.
CodePudding user response:
The solution was, as written in the comments:
Run the program in the Terminal, not in the QT Creator's Output Termina. In the output Terminal you cannot type any input.
Flush the buffer because the text lies in the buffer until a endl or a flush occurs.