Results 1 to 2 of 2

Thread: problem with reading input from user

  1. #1
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Question problem with reading input from user

    hi guys....
    I have a problem while i m try reading some input from the console user....check out the code below:
    #include <QTextStream>
    #Include <QString>
    int main()
    {
    1 using namespace std;
    2 QTextStream cin(stdin);
    3 QTextStream cout(stdout);
    4
    5 QString str;
    6 cout<< "enter text:"<<endl;
    7 str = cin.readLine();
    8 cout<<"the length of text is: \n"<<str.length()<<endl;
    9 return 0;
    }
    when i execute this prog it starts taking input from me endlessly...i mean d control wont go the 8th line as shown in code to calculate d length....
    Any help welcome...
    thnx...

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem with reading input from user

    remove the "using namespace std;" line; it is not needed.
    anyway it is confusing as then it is "unclear" if cout is yours or std::cout.

    HTH

Similar Threads

  1. problem with reading text files
    By Axsis in forum Newbie
    Replies: 1
    Last Post: 25th April 2008, 12:29
  2. Replies: 9
    Last Post: 13th February 2008, 13:23
  3. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  4. problem with reading input data in qt
    By Ahmad in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2007, 10:58
  5. Problem with reading a file
    By Buhmann in forum Qt Programming
    Replies: 11
    Last Post: 17th February 2006, 13:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.