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

R

Rakesh Kumar

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

Victor Bazarov

Rakesh said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top