STL container class overview

Source: Internet
Author: User

There are two types of containers in STL:Sequential containerAndAssociated container.

Ordered container: vector, list, deque

Associated containers: map, multimap, set, and Multiset

Both types of containers provide insert () for inserting elements, and erase () deletes elements from the container.

In addition, ordered containers also provide push_back () and pop_back (). The former adds elements to the end of the container, and the latter deletes elements from the end.

For ordered containers, especially vector, end access is fast and inexpensive.

The list and deque methods in the ordered container also provide the start-end access methods push_front () and pop_front ().


Method for accessing elements in a container

1. iterator

Both the sequential container and the associated container provide the member functions begin () and end (), which return the iterator pointing to the start position and end position of the container respectively.

2. Find ()

The associated container also provides the find () member function, which uses keywords to locate an element in the associated container.

3. Vector []

Vector is a dynamic array that supports the subscript index method of the array to access elements.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.