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

后端 未结 7 1989
刺人心
刺人心 2020-11-27 18:38

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条回答
  •  我在风中等你
    2020-11-27 18:59

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

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

提交回复
热议问题