codeGK
Code it ALL
C++ Vectors - CodeGK
♦ C++ Vectors

♣ About C++ Vectors

Vector is a C++ library which provides facilities of dynamic memory allocated array.
There exist various methods for Vectors which can be used for optimized implementation.
Below is a tabular explanation of some of the popular Vector Methods
Table Info
MethodWorking
pushback()Add element at the end
pop_back()Delete Last element
empty()Test whether the vector is empty
erase()Erase elements
size()Returns size of the vector
swap()Swap Content
reserve()Request a change in capacity
resize()Change size
begin()Return iterator to Beginning
end()Return iterator to End
rbegin()Return reverse iterator to reverse beginning
rend()Return reverse iterator to reverse end
cbegin()Return const_iterator to Beginning
cend()Return const_iterator to End
crbegin()Return const_reverse_iterator to reverse Beginning
crend()Return const_reverse_iterator to reverse End

♣ Example1: push_back() in vectors C++

In this example, push_back() is illustrated.
Example
Input:
Output:

♣ Example2: pop_back() in vectors C++

In this example, pop_back() is illustrated.
Example
Input:
Output:

♣ Example3: empty() in vectors C++

In this example, empty() is illustrated.
Example
Input:
Output:

♣ Example4: size() in vectors C++

In this example, size() is illustrated.
Example
Input:
Output:
Prev_LessonNext_Lesson