Introduction to Vector structure usage of C + + STL Library

Source: Internet
Author: User

What is STL is not introduced, here mainly introduce the common use of vectors in the library for easy reference later.

Vector member functions

Function

Expression

C.assign (Beg,end)

C.assign (N,elem)

assigns the data in the [beg; end] interval to c.

assigns a copy of n elem to c.

c.at (IDX)

Returns the index IDX refers to the data, if the IDX is out of bounds, throws Out_of_range.

C.back ()

Returns the last data without checking to see if the data exists.

C.begin ()

Returns a data that is valued by the iterator.

C.capacity ()

Returns the number of data in the container.

C.clear ()

Removes all data from the container.

C.empty ()

Determines whether the container is empty.

C.end ()

Points to the last data address in the iterator.

C.erase (POS)

C.erase (Beg,end)

Deletes data from the POS location and returns the location of the next data.

Delete the data from the [Beg,end] interval and return to the location of the next data.

C.front ()

Returns the first data.

Get_allocator

Use the constructor to return a copy.

C.insert (Pos,elem)

C.insert (Pos,n,elem)

C.insert (Pos,beg,end)

inserts a elem copy at the POS location and returns the new data location.

inserts n elem data at the POS location . no return value.

inserts the data in the [Beg,end] interval at the POS location. no return value.

C.max_size ()

Returns the maximum number of data in a container.

C.pop_back ()

Delete the last data.

C.push_back (Elem)

Add a data to the trailer.

C.rbegin ()

Returns the first data for a reverse queue.

C.rend ()

Returns the next position of the last data in a reverse queue.

C.resize (num)

Re-specify the length of the queue.

C.reserve ()

Keep the appropriate capacity.

C.size ()

Returns the number of actual data in the container.

c1.swap (C2)

swap (C1,C2)

Swaps c1 and c2 elements.

The same action.

Vector<elem> C

Vector <Elem> C1 (C2)

Vector <Elem> C (n)

Vector <Elem> C (n, Elem)

Vector <Elem> C (beg,end)

c.~ Vector <Elem> ()

Create an empty vector.

Copy a vector.

Create a vector that contains n data, and the data is constructed by default.

Create a vector containing n elem copies .

Create a vector with an interval of [Beg;end] .

Destroys all data and frees up memory.

Vector Operation

Function

Describe

Operator[]

Returns a reference to the specified position in the container.

Non-timed replenishment

Introduction to Vector structure usage of C + + STL Library

Related Article

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: info-contact@alibabacloud.com 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.