vector::reserve
为向量对象保留最小的存储长度,必要时为其分配空间。
void reserve( size_type _Count );
参数
- _Count
要分配给向量的最小存储长度。
示例
// vector_reserve.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector<int> v1;
v1.push_back(1);
cout << "Current capacity of v1 = "
<< v1.capacity( ) << endl;
v1.reserve(20);
cout << "Current capacity of v1 = "
<< v1.capacity( ) << endl;
}
要求
标头:<vector>
命名空间: std