自考新教材-p326_3(1)

源程序:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
int i;
ofstream ftxt1;
ftxt1.open("c:\tmp\xt1.txt",ios::out);
for (i = 1; i < 10; i++)
ftxt1 << i << ' ';
ftxt1.close();
ifstream ftxt2;
ftxt2.open("c:\tmp\xt1.txt",ios::in);
while (!ftxt2.eof())
{
ftxt2 >> i >> i;
cout << i << endl;
}
ftxt2.close();
system("pause");
return 1;

}

运行结果:

文件xt1.txt的内容如下:

 屏幕显示结果如下:

原文地址:https://www.cnblogs.com/duanqibo/p/12264598.html