how to pre-allocate memory for a std::string object?

Viewed 40515

I need to copy a file into a string. I need someway to preallocate memory for that string object and a way to directly read the file content into that string's memory?

7 Answers

std::string::resize() actually allocates the required space.

std::string::reserve() may not (it's a request).

Related