Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created November 16, 2019 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinniefalco/3a3ff03a96379e6969135c547a07f565 to your computer and use it in GitHub Desktop.
Save vinniefalco/3a3ff03a96379e6969135c547a07f565 to your computer and use it in GitHub Desktop.
inline
std::string
read_file( char const* path )
{
std::string s;
file f( path, "r" );
s.resize(512);
std::size_t len = 0;
for(;;)
{
// read the next chunk of the file
len += f.read( &s[0] + len, s.size() - len);
s.resize(len);
if( f.eof() )
break;
s.reserve( s.capacity() + 1);
s.resize( s.capacity() );
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment