Something I have in most of my programs:
/** Read file into string. */
inline std::string slurp (const std::string& path) {
std::ostringstream buf;
std::ifstream input (path.c_str());
buf << input.rdbuf();
return buf.str();
}
Can be placed in a header.
I think I have found it here: https://stackoverflow.com/a/116220/257568