Search
 
SCRIPT & CODE EXAMPLE
 

CPP

methods available for a stl vector

refer to this link :-
https://www.geeksforgeeks.org/vector-in-cpp-stl/

Capacity

size() – Returns the number of elements in the vector.
max_size() – Returns the maximum number of elements that the vector can hold.
capacity() – Returns the size of the storage space currently allocated to the vector expressed as number of elements.
resize(n) – Resizes the container so that it contains ‘n’ elements.
empty() – Returns whether the container is empty.
shrink_to_fit() – Reduces the capacity of the container to fit its size and destroys all elements beyond the capacity.
reserve() – Requests that the vector capacity be at least enough to contain n elements.

Element access:

reference operator [g] – Returns a reference to the element at position ‘g’ in the vector
at(g) – Returns a reference to the element at position ‘g’ in the vector
front() – Returns a reference to the first element in the vector
back() – Returns a reference to the last element in the vector
data() – Returns a direct pointer to the memory array used internally by the vector to store its owned elements.

Modifiers:

assign() – It assigns new value to the vector elements by replacing old ones
push_back() – It push the elements into a vector from the back
pop_back() – It is used to pop or remove elements from a vector from the back.
insert() – It inserts new elements before the element at the specified position
erase() – It is used to remove elements from a container from the specified position or range.
swap() – It is used to swap the contents of one vector with another vector of same type. Sizes may differ.
clear() – It is used to remove all the elements of the vector container
emplace() – It extends the container by inserting new element at position
emplace_back() – It is used to insert a new element into the vector container, the new element is added to the end of the vector

All Vector Functions :

vector::begin() and vector::end()
vector rbegin() and rend()
vector::cbegin() and vector::cend()
vector::crend() and vector::crbegin()
vector::assign()
vector::at()
vector::back()
vector::capacity()
vector::clear()
vector::push_back()
vector::pop_back()
vector::empty()
vector::erase()
vector::size()
vector::swap()
vector::reserve()
vector::resize()
vector::shrink_to_fit()
vector::operator=
vector::operator[]
vector::front()
vector::data()
vector::emplace_back()
vector::emplace()
vector::max_size()
vector::insert()

Comment

PREVIOUS NEXT
Code Example
Cpp :: currency converter c++ 
Cpp :: find kth max and min element in an array 
Cpp :: function in c++ 
Cpp :: how to write hello world in c++ 
Cpp :: how to know datatype of something in c++ 
Cpp :: c++ filesystem read directory 
Cpp :: c++ int length 
Cpp :: remove element from vector c++ 
Cpp :: c++ check if string is isogram 
Cpp :: sum of row s2 d array c++ 
Cpp :: power of a number 
Cpp :: C++ code for Dijkstra’s Algorithm 
Cpp :: operand-- c++ 
Cpp :: what is meant by pragma once in c++ 
Cpp :: quicksort geeksforgeeks 
Cpp :: inserting element in vector in C++ 
Cpp :: cpp define function 
Cpp :: best time to buy and sell stock leetcode solution 
Cpp :: difference between --a and a-- c++ 
Cpp :: c++ print text 
Cpp :: prime or not in cpp 
Cpp :: resize vector c++ 
Cpp :: qt make widget ignore mouse events 
Cpp :: Translation codeforces in c++ 
Cpp :: Lambda capture as const cpp 
Cpp :: how to declare a 2d vector stack 
Cpp :: size of string c++ 
Cpp :: 344. reverse string c++ 
Cpp :: files in c++ 
Cpp :: int to string C++ Using stringstream class 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =