读取输出:
QFile file("D:/Englishpath/QTprojects/1.dat"); if(!file.open(QIODevice::ReadOnly)) { qDebug()<<"Can‘t open the file!"<<endl; } QTextStream in(&file); while( !in.atEnd()) { QString line = in.readLine(); qDebug() << line; }
或
QFile file("D:/Englishpath/QTprojects/1.dat"); if(!file.open(QIODevice::ReadOnly)) { qDebug()<<"Can‘t open the file!"<<endl; } QTextStream stream(&file); QString line_in; stream.seek(file.size());//将当前读取文件指针移动到文件末尾 int count = 0; while(count < 10) { stream << QObject::trUtf8("新建行:") <<++count<<"/n"; } stream.seek(0);//将当前读取文件指针移动到文件开始 while( !stream.atEnd()) { line_in = stream.readLine(); qDebug() << line_in; }
【转载自】
Qt之文件操作 - liuhongwei123888的专栏 - CSDN博客 https://blog.csdn.net/liuhongwei123888/article/details/6084761
原文地址:https://www.cnblogs.com/wxl845235800/p/10770599.html
时间: 2024-10-08 23:19:34