#include <QtCore\QFile>
#include <iostream>
#include <QtCore\QIODevice>
using namespace std;
int main(int argc,char **argv)
{
// char line[80];
qint64 lineLength;
cout<<"Hello, world!"<<endl;
QFile qfile("rwfile.txt");
if(qfile.open( QIODevice::ReadOnly)) {
char buf[1024];
while ( !qfile.atEnd())
{
lineLength = qfile.readLine(buf, sizeof(buf));
if (lineLength != -1) {
cout<<buf<<endl;
}
}
qfile.close();
}
else
{
cout<<" ERROR: CAN'T OPEN TIS FILE!"<<endl;
}
return 0;
这是完整版,非常感谢楼上提醒!
}