读:

 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 }

 

相关文章:

  • 2021-07-01
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-09-07
  • 2021-11-17
  • 2021-11-26
相关资源
相似解决方案