QT文件读写

/*
//文件读取
QFile f("c:\\t.txt");
if(!f.open(QIODevice::WriteOnly | QIODevice::Text))
{
qDebug() << "Open failed";
return -1;
}
QTextStream txtOutput(&f);
QString s1("123");
quint32 n1(123);
txtOutput << s1 << " " << "caichao" << endl;
txtOutput << n1 << " " << 888 << endl;
f.close();
*/

///*
//读文件
QFile f("c:\\t.txt");
if(!f.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Open failed";
return -1;
}
QTextStream txtInput(&f);
QString lineStr;
while(!txtInput.atEnd())
{
lineStr = txtInput.readLine();
QStringList strList = lineStr.split(" ");
qDebug() << strList;
}
f.close();
//*/

原文地址:https://www.cnblogs.com/hermit/p/3553203.html