I got to find that we could read the contents of a file into a std::vector like this:
ifstream fin(..., ios::in);
std::vector<char> buf(
std::istreambuf_iterator<char>(fin),
std::istreambuf_iterator<char>());
Will this method cause plenty of memory reallocation like when I call buf.push_back(); for many times? What is the fastest or best method to read a file into a std::vector?
Edit: By the way, I find there is a method to read a file into a stringstream:
stringstream ss;
ifstream fin(..., ios::in);
fin >> ss.rdbuf();
Will this method have same problem of memory reallocating ?