Read whole ASCII file into C++ std::string [duplicate]
There are a couple of possibilities. One I like uses a stringstream as a go-between: std::ifstream t(“file.txt”); std::stringstream buffer; buffer << t.rdbuf(); Now the contents of “file.txt” are available in a string as buffer.str(). Another possibility (though I certainly don’t like it as well) is much more like your original: std::ifstream t(“file.txt”); t.seekg(0, std::ios::end); size_t … Read more