size

Syntax:

    #include <vector>
    size_type size() const;

The size() function returns the number of elements in the current vector.

If you wish to know if your vector is empty, it is usually preferable (for clarity, if nothing else) to call the empty() member function, rather than checking size against 0.

Note that this is different from the capacity() member function, which returns how many elements the vector could hold.

Related Topics: capacity, empty, max_size, resize