Read a whole file into a std::string

A simple way to read a whole file into a std::string.

#include <fstream>
#include <sstream>
...
std::ifstream file( "a.txt" );
std::stringstream buffer;
buffer << file.rdbuf();
std::string content = buffer.str();

Leave a Reply

Your email address will not be published. Required fields are marked *