- 论坛徽章:
- 0
|
写了个复制文件内容的代码为什么在GCC就编不通呢》???- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- ifstream open_file_in(string str)
- {
- ifstream fin;
- fin.open(str);
- return fin;
- }
- ofstream open_file_out(string str)
- {
- ofstream fout;
- fout.open(str,fstream::out|fstream::app);
- return fout;
- }
- int main(void)
- {
- string file_name;
- cout<<"pealse input a filename and its path"<<endl;
- inputname: cin>>file_name;
- ifstream fin;
- fin=open_file_in(file_name);
- int no=0;
- if(!fin)
- {
- no++;
- if(no!=3)
- {cerr<<"the filename is wrong please input a filename again"<<endl;
- goto inputname;
- }
- else
- {
- cerr<<"the program will close"<<endl;
- exit(1);
- }
- }
- ofstream fout;
- string out_file;
- cout<<"please output a file name for output"<<endl;
- cin>>out_file;
- fout=open_file_out(out_file);
- string tmp;
- while(getline(fin,tmp))
- {
- fout<<tmp;
- }
- fin.close();
- fout.close();
- return 0;
- }
复制代码 |
|