#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
}
#include <vector>
int main () {
std::vector<int> v;
auto size = v.size();
}
// CPP program to create an empty vector
// and push values one by one.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n = 3;
// Create a vector of size n with
// all values as 10.
vector<int> vect(n, 10);
for (int x : vect)
cout << x << " ";
return 0;
}
#include<iostream>
#include<vector>
using namespace std;
int main(){
//Creation of integer vector
vector<int> vectorArray {1,2,3,4,5,6,7,8,9};
//Created vector has 9 elements on it
int sizeOf_vectorArray= vectorArray.size();
cout<<sizeOf_vectorArray; // Output will be 9
vectorArray.push_back(10); // 10 will be added in the end of the vector
sizeOf_vectorArray=vectorArray.size();
cout<<sizeOf_vectorArray; // Output will be 10
vectorArray.push_front(0); //0 will be added in the begining of the vector
sizeOf_vectorArray=vectorArray.size();
cout<<sizeOf_vectorArray; // Output will be 11
return 0;
}
void resize (size_type n, value_type val = value_type());
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
void resize (size_type n);
void resize (size_type n, const value_type& val);
// create a vector with 20 integer elements
std::vector<int> arr(20);
for(int x = 0; x < 20; ++x)
arr[x] = x;