共用方式為


vector::size (STL/CLR)

計數項目的數目。

    size_type size();

備註

成員函式會傳回受控制序列的長度。 您可以用它來判斷目前在受控制序列的項目數目。 如果您很在意是否該序列擁有非零值的大小,請參閱vector::empty (STL/CLR)()。

範例

// cliext_vector_size.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 each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
    System::Console::WriteLine("size() = {0} starting with 3", c1.size()); 
 
// clear the container and reinspect 
    c1.clear(); 
    System::Console::WriteLine("size() = {0} after clearing", c1.size()); 
 
// add elements and clear again 
    c1.push_back(L'a'); 
    c1.push_back(L'b'); 
    System::Console::WriteLine("size() = {0} after adding 2", c1.size()); 
    return (0); 
    } 
 
  

需求

標頭: < cliext/向量 >

Namespace: cliext

請參閱

參考

vector (STL/CLR)

vector::empty (STL/CLR)