Are there any simple way to read all text from a small text file into a std::string with C++ STL iostream?
I have tried something like
ifstream f("file.txt");
stringstream ss;
while(!f.eof()){
array<char, READ_SIZE> buf;
auto size = f.rdbuf()->sreadn(buf.data(), buf.size());
if(size==0)break;
ss<<string(buf.data(), size);
}
string str=ss.str();
Any better way to do that?
1 Answer