4 /* QTextStreams look a lot like iostreams,
5 we just have to point them to the right place. */
8 QTextStream qstd::cin(stdin, QIODevice::ReadOnly);
9 QTextStream qstd::cout(stdout, QIODevice::WriteOnly);
10 QTextStream qstd::cerr(stderr, QIODevice::WriteOnly);
14 /* Namespace members are like static class members */
15 bool qstd::yes(QString question) {
17 cout << QString(" %1 [y/n]? ").arg(question);
20 return (ans.toUpper().startsWith("Y", Qt::CaseInsensitive));
24 bool qstd::more(QString s) {
25 return yes(QString("Another %1").arg(s));
29 int qstd::promptInt(int base /* =10 */) { /* Usage: int n = promptInt(); */
33 cout << ": " << flush;
35 numstr = cin.readLine();
36 result = numstr.toInt(&ok, base);
38 cout << "Invalid number. Try again: ";
47 double qstd::promptDouble() { /* Usage: double d = promptDouble(); */
52 numstr = cin.readLine();
53 result = numstr.toDouble(&ok);
55 cout << "Invalid number. Try again: ";
64 void qstd::promptOutputFile(QFile& outfile) {
67 cout << "Please enter the file name for saving this data: ";
69 filename = cin.readLine();
70 outfile.setFileName(filename);
71 bool fileExists = outfile.open(QIODevice::ReadOnly);
74 if (yes("File already exists ... Ok to overwrite"))
81 outfile.open(QIODevice::WriteOnly);
82 cout << filename << " open for writing ...\n";
87 void qstd::promptInputFile(QFile& infile) {
90 cout << "Name of the file to be read: ";
92 filename = cin.readLine();
93 infile.setFileName(filename);
94 bool fileExists = infile.open(QIODevice::ReadOnly);
97 cout << "File does not exist ... Please try again. \n";
101 cout << filename << " open for reading ...\n";