vector::swap function


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

Link:vector::reserve function

Code example

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

vecSt1.reserved(3) ;

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

Output

3
2

Link:vector::capacity function