要想像c/c++那样使用cin, cout, cerr, 必须将它们先定义QTextStream对象。
QTextStream cin(stdin, QIODevice::ReadOnly);
QTextStream cout(stdout, QIODevice::WriteOnly);
QTextStream cerr(stderr, QIODevice::WriteOnly);
正常读写txt流程:
QFile* fileIn = new QFile(ui->lineEdit->text()); // 从控件lineEdit取文件名,利用QFile打开文件
// 通过 QFileDialog::getSaveFileName 获取保存文件名,对话框显示控件lineEdit内容,修改后即可传给fileName
QString fileName = QFileDialog::getSaveFileName(this, tr("保存文件"), ui->lineEdit->text(), tr("TXT(*.TXT)"));
QFile* fileOut = new QFile(fileName); // 利用QFile打开文件
if(!fileIn->open(QIODevice::ReadOnly | QIODevice::Text)) //打开文件
{
cout << "fi