| 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
.
|
|
|
|

|
Related Articles |
|
|