list::size (STL/CLR)
計數項目的數目。
size_type size();
備註
成員函式傳回受控制序列的長度。 您可用它來決定受控制序列中目前的項目數目。 如果您只想知道序列的大小是否非零,請參閱 list::empty (STL/CLR)()。
範例
// cliext_list_size.cpp
// compile with: /clr
#include <cliext/list>
int main()
{
cliext::list<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/list>
命名空間: cliext