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();
//*/

posted @ 2014-02-17 20:35  西山翠冷  阅读(282)  评论(0编辑  收藏  举报