468,513 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

STL std::string difference between reserve and resize ()

Hi -
I am going through the STL API for std::string.
I see 2 methods called reserve(sz) and resize(sz) .

I am just curious if they actually implement the same and if not ,
what are the scenarios in which one would be preferable over another.
Dec 18 '07 #1
2 7517
Rakesh Kumar wrote:
I am going through the STL API for std::string.
I see 2 methods called reserve(sz) and resize(sz) .

I am just curious if they actually implement the same and if not ,
Not.
what are the scenarios in which one would be preferable over another.
'resize' changes the size. 'reserve' changes the capacity (so that
some growth didn't require reallocation. 'reserve' does not change
the size. They mean (and do) different things. Use each one when
appropriate.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 18 '07 #2
On Dec 18, 9:11 pm, Rakesh Kumar <rakesh.use...@gmail.comwrote:
Hi -
I am going through the STL API for std::string.
I see 2 methods called reserve(sz) and resize(sz) .

I am just curious if they actually implement the same and if not ,
what are the scenarios in which one would be preferable over another.
http://www.cppreference.com/cppstring/index.html
Dec 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Axel | last post: by
4 posts views Thread by __PPS__ | last post: by
16 posts views Thread by Khuong Dinh Pham | last post: by
15 posts views Thread by roberts.noah | last post: by
25 posts views Thread by Bala2508 | last post: by
5 posts views Thread by TBass | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.