Skip to content

Instantly share code, notes, and snippets.

@woxtu
Created November 19, 2013 11:24
Show Gist options
  • Save woxtu/7543972 to your computer and use it in GitHub Desktop.
Save woxtu/7543972 to your computer and use it in GitHub Desktop.
Read the whole file into std::string in C++.
#include <fstream>
#include <string>
#include <iostream>
int main() {
std::ifstream stream{"fujiyama.txt"};
std::string buffer{std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>()};
std::cout << buffer << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment