自考新教材-p326_3(2)

源程序:

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

int main()
{
int i;
ifstream f1("c:\\tmp\\xt1.txt",ios::in);
fstream f2("c:\\tmp\\xt2.txt",ios::out|ios::binary);
while (!f1.eof())
{
f1 >> i;
i = i * 5;
f2.write((char *)&i,sizeof(int));
}
f1.close();
f2.close();
f2.open("c:\\tmp\\xt2.txt",ios::in|ios::binary);
do
{
f2.read((char *)&i,sizeof(int));
cout << i << ",";
} while (i<30);
cout << endl;
f2.close();
system("pause");
return 1;
}

运行结果:

 

posted @ 2020-02-05 17:34  bobo哥  阅读(143)  评论(0编辑  收藏  举报