JPGygax68
8/14/2013 - 3:18 PM

C++: read a whole file into a string.

C++: read a whole file into a string.

using namespace std;

ifstream fs(filename);
string s;

fs.seekg(0, ios::end);   
s.reserve( (size_t) fs.tellg() );
fs.seekg(0, ios::beg);

s.assign( istreambuf_iterator<char>(fs), istreambuf_iterator<char>() );