Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to re-initialize a vector

Status
Not open for further replies.

Lorey

Programmer
Feb 16, 2003
88
SG
Hi!

Anybody knows how to reinitialize a vector?
Like for example, in the code below, I already put values inside emergencyCallPriorities.

std::vector<RadioPriority> emergencyCallPriorities

I need to reset all the values. and will put a new values again....
 
thanks!

i just found out that it is equals to using .clear().
 
.clear() will erase all elements in the vector, but it will not shrink the size of the vector. If you need to clear the vector and shrink the size, use the swap trick:
Code:
vector<something> v;
...
vector<something>().swap( v );  // Clear & minimize v.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top