Friday 27 February 2015

Sample C++ program to illustrate file read and file write operations

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char * argv[])
{
  if(argc < 3)
  {
    cout<< "Please pass 2 file names"<<endl;
    return 0;
  }
  else
  {
    string line;

    fstream ifile, ofile;
    ifile.open(argv[1], ios::in);
    ofile.open(argv[2], ios::out);

    while(getline(ifile, line))
    {
      ofile << line << endl ;
    }

    return 1;
  }
}

No comments:

Post a Comment