Skip to content

Instantly share code, notes, and snippets.

@JPGygax68
Last active September 18, 2017 19:06
Show Gist options
  • Save JPGygax68/6232062 to your computer and use it in GitHub Desktop.
Save JPGygax68/6232062 to your computer and use it in GitHub Desktop.
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>() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment