#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
class Copy_file
{
public:
Copy_file();
~Copy_file();
void Copy_files();
void in_file();
void out_file();
protected:
private:
fstream infl;
fstream outf;
char file1[20];
char file2[20];
};
Copy_file::Copy_file()
{
cout<<"请输入文件名:";
cin>>file1;
infl.open(file1,ios::in|ios::binary);
if (!infl)
{
cout<<"不能打开原文件:"<<file1<<endl;
abort();
}
cout<<"请输入目的文件名:";
cin>>file2;
outf.open(file2,ios::in|ios::out|ios::binary);
if (!outf)
{
cout<<"不能打开目的文件:";
abort();
}
}
Copy_file::~Copy_file()
{
infl.close();
outf.close();
}
void Copy_file::Copy_files()
{
char ch;
infl.seekg(0);
infl.get(ch);
while(!infl.eof())
{
if (ch>='a'&&ch<='z')
outf.put(ch);
infl.get(ch);
}
}
void Copy_file::in_file()
{
char ch;
infl.close();
infl.open(file1,ios::in|ios::binary);
infl.get(ch);
while(!infl.eof())
{
cout<<ch;
infl.get(ch);
}
cout<<endl;
}
void Copy_file::out_file()
{
char ch;
outf.seekp(0);
outf.get(ch);
while(!outf.eof())
{
cout<<ch;
outf.get(ch);
}
cout<<endl;
}
int main()
{
Copy_file cf;
cf.Copy_files();
cout<<"原文件中内容:"<<endl;
cf.in_file();
cout<<"目的文件中内容:"<<endl;
cf.out_file();
system("pause");
return 0;
}
c++输入输出 流的应用
最新推荐文章于 2022-04-21 10:07:32 发布