vector::capacity (STL/CLR)
報告容器配置儲存區的大小。
size_type capacity();
備註
成員函式會傳回目前配置來保留受控制的序列,至少相等於值的儲存區vector::size (STL/CLR)()。您可以用它來判斷多少容器可以成長之前就必須重新配置受控制序列的儲存區。
範例
// cliext_vector_capacity.cpp
// compile with: /clr
#include <cliext/vector>
int main()
{
cliext::vector<wchar_t> c1;
c1.push_back(L'a');
c1.push_back(L'b');
c1.push_back(L'c');
// display initial contents " a b c"
for (int i = 0; i < c1.size(); ++i)
System::Console::Write(" {0}", c1.at(i));
System::Console::WriteLine();
// increase capacity
cliext::vector<wchar_t>::size_type cap = c1.capacity();
System::Console::WriteLine("capacity() = {0}, ok = {1}",
cap, c1.size() <= cap);
c1.reserve(cap + 5);
System::Console::WriteLine("capacity() = {0}, ok = {1}",
c1.capacity(), cap + 5 <= c1.capacity());
return (0);
}
描述
請注意實際的容量,可能會有所不同這裡顯示的值,這麼久所有ok測試均回報為 true。
需求
標頭: < cliext/向量 >
Namespace: cliext