Skip to content

Instantly share code, notes, and snippets.

@1995eaton
Created December 2, 2014 01:40
Show Gist options
  • Save 1995eaton/98fb8b43c2723091fbfe to your computer and use it in GitHub Desktop.
Save 1995eaton/98fb8b43c2723091fbfe to your computer and use it in GitHub Desktop.
Fast one-liner to read a file into a string.
#include <iostream>
#include <sstream>
#include <fstream>
int main() {
std::string data = static_cast<std::ostringstream&>
( std::ostringstream() << std::ifstream("data.txt").rdbuf() ).str();
std::cout << data << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment