由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - std::string::reserve()
相关主题
c/c++/java的对象/结构输入字符串插入
I like this one.reverse words, not the Microsoft one!!!
c++ iterator 弱问A question about c++ pointer
一个C++ operator new的重载问题Pattern matching
关于Java一个小程序的结果[合集] c++的题
question on reserve() in vector container.数据类型判断
请教一个c++ map问题[合集] 一个依赖于平台的memory问题
问一个C++ set和unordered_set iterator的问题xcode for leopard BUG??? help.
相关话题的讨论汇总
话题: reserve话题: string话题: arg话题: res话题: capacity
进入Programming版参与讨论
1 (共1页)
t****d
发帖数: 8
1
看到网上一个解释:
void reserve(uint res_arg = 0)
change the capacity of a String to the maximum of res_arg and size(). This
may be an increase or a decrease in the capacity.
这个对吗? 我做了个简单的测试,跟踪 i 的值,但是在reserve前后没有变化,哪位
指点一下,谢谢了。
std::string str1("abcdefgh");
int i=str1.size(); // 结果是8
i=str1.capacity(); // 结果是15
str1.reserve(4);
i=str1.capacity(); // 结果是15
i=str1.size(); // 结果是8
t****t
发帖数: 6806
2
official document is as follows:
void reserve(size_type res_arg=0);
1 The member function reserve() is a directive that informs a
basic_string object of a planned change in size, so that it can manage
the storage allocation accordingly.
Effects:
After reserve(), capacity() is greater or equal to the argument of
reserve. [Note: Calling reserve() with a res_arg argument less than
capacity() is in effect a non-binding shrink request. A call with
res_arg <=

【在 t****d 的大作中提到】
: 看到网上一个解释:
: void reserve(uint res_arg = 0)
: change the capacity of a String to the maximum of res_arg and size(). This
: may be an increase or a decrease in the capacity.
: 这个对吗? 我做了个简单的测试,跟踪 i 的值,但是在reserve前后没有变化,哪位
: 指点一下,谢谢了。
: std::string str1("abcdefgh");
: int i=str1.size(); // 结果是8
: i=str1.capacity(); // 结果是15
: str1.reserve(4);

1 (共1页)
进入Programming版参与讨论
相关主题
xcode for leopard BUG??? help.关于Java一个小程序的结果
请教如何使用qsort() to sort string.question on reserve() in vector container.
求改进小函数请教一个c++ map问题
问一个C++ String的初始化问题问一个C++ set和unordered_set iterator的问题
c/c++/java的对象/结构输入字符串插入
I like this one.reverse words, not the Microsoft one!!!
c++ iterator 弱问A question about c++ pointer
一个C++ operator new的重载问题Pattern matching
相关话题的讨论汇总
话题: reserve话题: string话题: arg话题: res话题: capacity