import vector c++ code example
Example 1: how to create a vector in c++
#include <vector>
using namespace std;
int main()
{
vector<int> vect;
vect.push_back(10);
for (int x : vect)
cout << x << " ";
return 0;
}
Example 2: std vector include c++
#include <vector>
std::vector<std::string> x;
Example 3: how to use vectors c++
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int size = 4;
vector<int> myVect (size, 4);
for (int i=0; i<size; i++) {
cout << "Vector index(" << i <<") is: "<< myVect[i] << endl;
}
return 0;
}