如何把文件中的數據讀入程序

#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;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章