1#include <vector>
2
3int main () {
4 std::vector<int> v;
5 auto size = v.size();
6}
1#include <vector>
2
3int main() {
4 std::vector<int> myVector = { 666, 1337, 420 };
5
6 size_t size = myVector.size(); // 3
7
8 myVector.push_back(399); // Add 399 to the end of the vector
9
10 size = myVector.size(); // 4
11}
1#include <iostream>
2#include <vector>
3using namespace std;
4
5int main() {
6 //vector element size
7 const int size = 4;
8 //vector with int data type
9 //all elements are equal to 4
10 vector<int> myVect (size, 4);
11
12 for (int i=0; i<size; i++) {
13 cout << "Vector index(" << i <<") is: "<< myVect[i] << endl;
14 }
15 return 0;
16}
1vector<int> a;
2//to directly find the size of the vector;
3//use a.size(;
4
5cout <<" " << a.size();
1#include <iostream>
2#include <vector>
3
4using namespace std;
5
6int main(void) {
7 vector<int> v;
8
9 cout << "Initial vector size = " << v.size() << endl;
10
11 v.resize(5, 10);
12 cout << "Vector size after resize = " << v.size() << endl;
13
14 cout << "Vector contains following elements" << endl;
15 for (int i = 0; i < v.size(); ++i)
16 cout << v[i] << endl;
17
18 return 0;
19}