#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("D:\\test1.txt"); // 创建输入流类对象并和磁盘文件绑定
if(!fin) {
cout << "can not open the file" << endl;
exit(1);
}
char one[64], two[64], three[64];
fin >> one ; //三次提取文本文件
fin >> two ;
fin >> three;
cout << one <<endl << two << endl << three <<endl;
fin.close();
return 0;
}
文本文件按如下方式创建
#include <iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{
ofstream fout("D:\\test1.txt");
if(!fout) {
cout << "can not open the file" << endl;
exit(1);
}
fout << "The contents of the file :" << endl;
fout << "opp is not difficult to learn," << endl;
fout << "as long as have this book." << endl;
fout.close();
return 0;
}
文本文件内容如下:
The contents of the file :
opp is not difficult to learn,
as long as have this book.
请问为什么输出结果不是三个 The 而是The contents of 呢?