#include <QtCore\QFile>
#include <iostream>
#include <QtCore\QIODevice>
#include <QtCore\QTextStream>
using namespace std;
int main(int argc,char **argv)
{
char line[512];
qint64 lineLength;
cout<<"Hello, world!"<<endl;
cout<<"Just a test!"<<endl;
cout<<"你好"<<endl;//此处原来写的是中文 “你好”
QFile qfile("rwfile.txt");
QFile ofile("ofile.txt");
if (qfile.open( QIODevice::ReadOnly))
{
if (ofile.open(QIODevice::WriteOnly))
{
QTextStream out(&ofile);
while ( !qfile.atEnd())
{
lineLength = qfile.readLine(line, sizeof(line));
if (lineLength != -1)
{
out<<line<<endl;
}
}
}
else
{
cout<<" ERROR: CAN'T OPEN TIS FILE====>ofile!"<<endl;
}
qfile.close();
ofile.close();
}
else
{
cout<<" ERROR: CAN'T OPEN TIS FILE====>qfile!"<<endl;
}
return 0;
}
此段代码在用
codeblocks编译环境(实际上海市GCC)中编译通过,运行正常,可惜的是codeblocks不支持中文输入,很遗憾,在此环境中头文件路径飞的指明,不知道是怎么一回事比如直接加<QFile>编译就不通过了,找不到QFile的定义 之类的问题 主要是找不到QFile类定义文件造成的!
如果在控制台下编译的话,编译时头文件包含区 只需<QFile>就可以了,不需要<QtCore\QFile>这样指定;执行的时候程序提示无法打开文件“ERROR: CAN'T OPEN TIS FILE====>qfile”,很郁闷!
请各位同仁帮一忙好吗?若果时间多的话,请详细说出问题原因!