#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//文件打开
fstream file1("1.txt",ios::in|ios::out|ios::app|ios::binary);
if(!file1)
{
file1.close();
cout<<"create err!!"<<endl;
}
fstream file2("2.txt",ios::in|ios::out|ios::app|ios::binary);
if(!file2)
{
file1.close();
cout<<"create err!!"<<endl;
}
//读取文件的内容
char buf[20];
while(!file1.eof())
{
file1.read(buf,20);
//写入数据到另一个文件中去
file2.write(buf,file1.gcount());
cout<<file1.gcount()<<endl; //返回读取的最后一次输入的字符数
}
file1.close();
return 0;
}
11-06
1200
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-12
1120
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-13
559
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)