cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : list : size
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
list
comparison operators
list::list
list::~list
member functions:
· list::assign
· list::back
· list::begin
· list::clear
· list::empty
· list::end
· list::erase
· list::front
· list::get_allocator
· list::insert
· list::max_size
· list::merge
· list::operator=
· list::pop_back
· list::pop_front
· list::push_back
· list::push_front
· list::rbegin
· list::remove
· list::remove_if
· list::rend
· list::resize
· list::reverse
· list::size
· list::sort
· list::splice
· list::swap
· list::unique

-

list::size public member function
size_type size() const; 

Return size

Returns the number of elements in the container.

Parameters

none

Return Value

The number of elements that conform the list's content.

Member type size_type is an unsigned integral type.

Example

// list::size
#include <iostream>
#include <list>
using namespace std;

int main ()
{
  list<int> myints;
  cout << "0. size: " << (int) myints.size() << endl;

  for (int i=0; i<10; i++) myints.push_back(i);
  cout << "1. size: " << (int) myints.size() << endl;

  myints.insert (myints.begin(),10,100);
  cout << "2. size: " << (int) myints.size() << endl;

  myints.pop_back();
  cout << "3. size: " << (int) myints.size() << endl;

  return 0;
}

Output:

0. size: 0
1. size: 10
2. size: 20
3. size: 19

Complexity

Constant.

See also

list::resize Change size (public member function)
list::max_size Return maximum size (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us