How to read file content into istringstream in C++?

Here is a C++ program to read file content into isstringstream in C++.


#include <fstream>
#include <sstream>
using namespace std;
int main() {
   ifstream is("a.txt", ios::binary );
   // get length of file:
   is.seekg (0, std::ios::end);
   long length = is.tellg();
   is.seekg (0, std::ios::beg);
   // allocate memory:
   char *buffer = new char [length];
   // read data as a block: (buffer,length);
   // create string stream of memory contents
   istringstream iss( string( buffer ) );
   // delete temporary buffer
   delete [] buffer;
   // close filestream


hi tutorialspoint