#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
}
vector<vector<int>> v(10, vector<int>(10));
// 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;
}
void resize (size_type n, value_type val = value_type());
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;