如何把文件中的数据读入程序

来源:互联网 发布:无法打开awrrpt.sql 编辑:程序博客网 时间:2024/05/22 07:05
#include <iostream>#include <string>#include <algorithm>#include <functional>#include <iterator>#include <vector>#include <fstream>using namespace std;int main(){   
  string input_file_name;  string output_file_name;  cout<<"input the in_file_name: "<<endl;  cin>>input_file_name;  cout<<"input the output_file_name: "<<endl;  cin>>output_file_name;  ifstream f_in(input_file_name.c_str()); ofstream f_out(output_file_name.c_str()); if(!f_in || !f_out) 
{   cout<<"can't open the file!"<<endl;   exit(0); }  istream_iterator<char> is(f_in); istream_iterator<char> eof;  vector<char> text;  copy(is,eof,back_inserter(text));   ostream_iterator<char> os(f_out,"");  copy(text.begin(),text.end(),os); cout<<"the copy is over ! "<<endl; return 0;}

0 0
原创粉丝点击