February 24, 2012

belamoor belamoor
Lab Rat
1 posts

QtCreator 2.4.1 console input

 

I’m somewhat new and C++ and just starting with Qt. Trying to run a very simple program in QtCreator, which uses console input on WinXP:

  1. #include <QString>
  2. #include <QTextStream>
  3. QTextStream cout(stdout);
  4. QTextStream cin(stdin);
  5.  
  6. int main() {
  7. cout << "Enter a sentence: ";
  8. s2 = cin.readLine();
  9. cout << "Here is your sentence:" << s2 << endl;
  10. cout << "The length of your sentence is: " << s2.length() << endl;
  11. return 0;
  12. }

But QTCreator’s application output doesn’t seem to allow typing in things. I’ve tried checking “Run in terminal” in Projects>Desktop>Run and the terminal shows up, but it seems kind of detached.It only contains “Press RETURN to close this window…” string printed and doesn’t seem to interact with the program anyhow. Thanks in advance.

2 replies

February 24, 2012

VanDerSam VanDerSam
Lab Rat
39 posts

After operator

  1. cout << "Enter a sentence: ";

you must insert operator

  1. cout.flush();

March 16, 2013

Eslam mahgoub Eslam mahgoub
Lab Rat
32 posts

Than You VanDerSam

 
  ‹‹ how to detect memory leaks      [Closed] Qt creator font render issue in Windows XP Korean version ››

You must log in to post a reply. Not a member yet? Register here!