Translations of this page?:
Table of Contents

C++ Vectors

Vectors contain contiguous elements stored as an array.

Accessing members of a vector can be done in constant time, appending elements to a vector can be done in amortized constant time, whereas locating a specific value or inserting elements into the vector takes linear time.

Constructors建立 vectors and initialize them with some data
Operatorscompare, assign, and access elements of a vector
assignassign elements to a vector
at傳回一個指定位置的元素的參考
back傳回一個指向最後一個元素的參考
beginreturns an iterator to the beginning of the vector
capacity傳回最多可以容納的元素個數
clear移除所有元素
empty判斷vector是否為空?若為空,則傳回true
endreturns an iterator just past the last element of a vector
erase從vector理移除一個元素
frontreturns a reference to the first element of a vector
insertinserts elements into the vector
max_sizereturns the maximum number of elements that the vector can hold
pop_back移除在vector最後一個元素
push_back在vector的最後新增一個元素
rbeginreturns a reverse_iterator to the end of the vector
rendreturns a reverse_iterator just past the beginning of the vector
reservesets the minimum capacity of the vector
resize調整 vector 大小
size傳回 vector 裡的元素個數
swapswap the contents of this vector with another

Notes:

Note that a boolean vector (vector<bool>) is a specialization of the vector template that is designed to use less memory. A normal boolean variable usually uses 1-4 bytes of memory, but a boolean vector should use only one bit per boolean value..

注意:

一個boolean vector, vector<bool>, 是一種為了節省記憶體空間使用所設計的一個特殊模板. 通常情況下, 一個boolean 變數使用 1-4個bytes. 但是 boolean vector 對每一個boolean值只使用1個bit..

 
• • • SitemapRecent changesRSScc