Changing the reserve memory of C++ vector

前端 未结 5 1349
情深已故
情深已故 2021-01-06 00:29

I have a vector with 1000 \"nodes\"

 if(count + 1 > m_listItems.capacity())
     m_listItems.reserve(count + 100);

The problem is I also

5条回答
  •  迷失自我
    2021-01-06 01:21

    You can swap it with a new vector that has desired capacity.

    vector< int > tmp;
    old.swap( tmp );
    

提交回复
热议问题