I'm new to both C++ and Qt. I'm reading an online book (http://www.ics.com/files/designpatterns/book/index.html) and am at Example 1.8. My code is exactly as theirs, but I cannot get to cin.readLine(); I can enter my sentence with whitespaces and hit <enter> a 100 times, but I never get to the next line of code. Can someone tell me why? Here is my code:
//#include <QtCore/QCoreApplication>
#include <QTextIStream>
#include <QString>
//#include <QFile>
QTextStream cout(stdout);
QTextStream cin(stdin);
int main()
{
//QCoreApplication a(argc, argv);
QString s1("This "), s2("is a "), s3("string");
s1 += s2; //concatenation
QString s4 = s1 + s3;
cout << s4 << endl;
cout << "The length of that string is " << s4.length() << endl;
cout << "Enter a sentence with whitespaces: " << endl;
// The following three lines of code never execute.
s2 = cin.readLine();
cout << "Here is your sentence: \n" << s2 << endl;
cout << "The length of your sentence is: " << s2.length() << endl;
return 0;
//return a.exec();
}


Reply With Quote

Bookmarks