Copy one file to another, a line at a time - C++ File Stream

C++ examples for File Stream:File Operation

Description

Copy one file to another, a line at a time

Demo Code

#include <string>
#include <fstream>
using namespace std;
int main() {/* www. j av  a  2 s .c  om*/
   ifstream in("s.cpp"); // Open for reading
      ofstream out("t.cpp"); // Open for writing
   string s;
   while(getline(in, s)) // Discards newline char
      out << s << "\n"; // ... must add it back
}

Related Tutorials