如何为std :: string对象预分配内存? [英] how to pre-allocate memory for a std::string object?

查看:839
本文介绍了如何为std :: string对象预分配内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将文件复制到字符串中。我需要某个地方为该字符串对象预先分配内存,并直接读取文件内容到该字符串的内存中。

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?

推荐答案

code> std :: string 还有一个 .reserve 方法

std::string also has a .reserve method.

这篇关于如何为std :: string对象预分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆