Read an entire file into a single string - C++ File Stream

C++ examples for File Stream:File Operation

Description

Read an entire file into a single string

Demo Code

#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main() {/*from  ww  w.  j a v  a2 s  .c o  m*/
   ifstream in("main.cpp");
   string s, line;
   while(getline(in, line))
      s += line + "\n";
   cout << s;
}

Result


Related Tutorials