diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index 7d247dd07..3951bbdd7 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -111,8 +111,10 @@ inline bool FileExists(const char *name) { inline bool LoadFile(const char *name, bool binary, std::string *buf) { std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in); if (!ifs.is_open()) return false; - *buf = std::string(std::istreambuf_iterator(ifs), - std::istreambuf_iterator()); + ifs.seekg(0, std::ios::end); + (*buf).resize(ifs.tellg()); + ifs.seekg(0, std::ios::beg); + ifs.read(&(*buf)[0], (*buf).size()); return !ifs.bad(); }