C++ vector::swap function

The C++ vector swap function swap the two vectors data.

void swap(vector& x);

Parameters:
x – A vector whose data is to be exchanged with.

Return type
void

This function will swap even the storage that is not occupied but reserved for the future use.

 vector<string>vecSt={ “New , “Chrome”} ,
vecSt1 ;

vecSt1.reserved(3) ;

cout<< vecSt.capacity() << endl
<< vecSt1.capacity( ) ;

Output

3
2




Leave a Reply

Your email address will not be published. Required fields are marked *