vector_functions_notes
vector_functions_notes
Introduction to vector
- std::vector is a dynamic array provided by the C++ Standard Template Library (STL).
Header file:
#include <vector>
Namespace:
1. Constructor Functions
- vector<T> v(n, val); -> Creates a vector with n elements, each of value val.
2. Capacity Functions
4. Modifiers
5. Iterators
- v.begin(), v.end()
- v.rbegin(), v.rend()
- v.cbegin(), v.cend()
- v.crbegin(), v.crend()
6. Relational Operators
7. Utility Functions
- std::swap(v1, v2)
- std::sort(v.begin(), v.end())
Example Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
v.push_back(40);
v.insert(v.begin() + 1, 15);
v.pop_back();
for (int x : v)
return 0;