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



 DEVELOP > c-Plus-Plus > STL std::string difference between reserve and resize ()

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Rakesh Kumar"
Date: 18 Dec 2007 01:11:25 PM
Object: 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.
.

User: "Ioannis Gyftos"

Title: Re: STL std::string difference between reserve and resize () 19 Dec 2007 03:06:46 AM
On Dec 18, 9:11 pm, Rakesh Kumar <rakesh.use...@gmail.com> wrote:

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
.

User: "Victor Bazarov"

Title: Re: STL std::string difference between reserve and resize () 18 Dec 2007 01:17:20 PM
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER