標籤:

7.18

#include <iostream>

#include <fstream>

#include <stdlib.h>

using namespace std;

class Copy_file{

private:

fstream inf;

fstream outf;

char file1[20];

char file2[20];

public:

Copy_file();

~Copy_file();

void Copy_files();

void in_file();

void outfile();

};

Copy_file::Copy_file(){

cout<<"請輸入源文件名:";

cin>>file1;

inf.open(file1,ios::in);

if(!inf){

cout<<"不能打開源文件:"<<file1<<endl;

abort();

}

cout<<"請輸入目的文件名:";

cin>>file2;

outf.open(file2,ios::in|ios::out);

if(!outf){

cout<<"不能打開目的文件:"<<file2<<endl;

abort();

}

}

Copy_file::~Copy_file(){

inf.close();

outf.close();

}

void Copy_file::Copy_files(){

char ch;

inf.seekg(0);

inf.get(ch);

while(!inf.eof()){

if(ch>=a&&ch<=z)

outf.put(ch);

inf.get(ch);

}

}

void Copy_file::in_file(){

char ch;

inf.close();

inf.open(file1,ios::in);

inf.get(ch);

while(!inf.eof()){

cout<<ch;

inf.get(ch);

}

cout<<endl;

}

void Copy_file::outfile(){

char ch;

outf.seekg(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.outfile();

return 0;

}

推薦閱讀:

楚河漢界
關於編程能力的思考
學習Git(二)基本操作
網路工程師的Python學習筆記+乾貨
沈向洋:You Are What You Write,大家都要看

TAG:編程 |