stl:deque:size

C++ Reference

size

Syntax:

#include <deque>
size_type size() const;

The size function returns the number of elements in the current deque.

For example:

deque<int> myints;
cout << "initial size: " << myints.size() << '\n';
 
for( int i = 0; i < 5; ++i ) myints.push_back(i);
cout << "after five additions: " << myints.size() << '\n';
 
myints.insert( myints.begin(), 5, 100 );
cout << "after five insertions: " << myints.size() << '\n';
 
myints.pop_back();
cout << "after a removal: " << myints.size() << '\n';

The above code produces the following output:

initial size: 0
after five additions: 5
after five insertions: 10
after a removal: 9

Related Topics: max_size, resize