ait-survey

[F] read_write_text-C++.cpp

Feb 27th, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<iomanip>
  4. #include<sstream>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char** argv)
  9. {
  10.  
  11.     if(argc!=3)
  12.     {
  13.         fprintf(stderr,"Usage: %s\n(1)Input_filename\n",argv[0]);
  14.         exit(1);
  15.     }
  16.    
  17.     ifstream ifs(argv[1]);
  18.     ofstream ofs(argv[2]);
  19.     string line;
  20.  
  21.     while(getline(ifs,line))
  22.     {
  23.  
  24.         int a,b;
  25.  
  26.         istringstream is(line);
  27.        
  28.         is  >> a
  29.             >> b;
  30.        
  31.         cout<< a <<" "<< b <<endl;
  32.         ofs << a <<" "<< b <<endl;
  33.  
  34.     }
  35.     ifs.close();
  36.     ofs.close();
  37.    
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment