Qt txt文件读写
作者:互联网
读:
1 void MainWindow::ReadTxt(QString filePath) 2 { 3 QFile file(filePath); 4 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) 5 { 6 while (!file.atEnd()) 7 { 8 QByteArray line = file.readLine(); 9 QString str(line); 10 } 11 12 file.close(); 13 } 14 }
写:
1 void WriteTxt(QString filePath, QString txt) 2 { 3 QFile file(filePath); 4 if (file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Append)) 5 { 6 QTextStream stream(&file); 7 stream << txt << "\n"; 8 file.close(); 9 } 10 }
标签:Qt,stream,filePath,读写,QString,file,QIODevice,txt 来源: https://www.cnblogs.com/warmlight/p/14230140.html