#include <vector>
int main() {
std::vector<int> myVector = { 666, 1337, 420 };
size_t size = myVector.size(); // 3
myVector.push_back(399); // Add 399 to the end of the vector
size = myVector.size(); // 4
}
vectorName.size();
vector<int> a;
//to directly find the size of the vector;
//use a.size(;
cout <<" " << a.size();
size() function is used to return the size of the vector container or the number of elements in the vector container.
using namespace std;
int main(){
vector<int> myvector{ 1, 2, 3, 4, 5 };
cout << myvector.size();
return 0;
}
//Output = 5
Code Example |
---|
Cpp :: append string cpp |
Cpp :: reading file c++ |
Cpp :: how to get the type of a variable in c++ |
Cpp :: how to use char in c++ |
Cpp :: size of array |
Cpp :: c++ splitstring example |
Cpp :: lutris |
Cpp :: declare nullptr c++ |
Cpp :: are strings mutable in c++ |
Cpp :: c++ how to add something at the start of a vector |
Cpp :: c++ code for bubble sort |
Cpp :: string to upper c++ |
Cpp :: filling 2d array with 0 c++ |
Cpp :: int to float c++ |
Cpp :: cpp create lambda with recursion |
Cpp :: insert a character into a string c++ |
Cpp :: how to get the time in c++ as string |
Cpp :: json::iterator c++ |
Cpp :: fizzbuzz c++ |
Cpp :: c++ contains |
Cpp :: doubly linked list in cpp |
Cpp :: struct c++ |
Cpp :: c function as paramter |
Cpp :: check if a key is in map c++ |
Cpp :: print hello world c++ |
Cpp :: c++ reverse part of vector |
Cpp :: initialize a vector to 0 |
Cpp :: dice combinations cses solution |
Cpp :: add matic mainnet to metamask mobile |
Cpp :: how to make a vector in c++ |