I can create an array and initialize it like this:
int a[] = {10, 20, 30};
How do I create a std::vector
and initialize it sim
There are various ways to hardcode a vector, i will share few ways:
// Create an empty vector
vector vect;
vect.push_back(10);
vect.push_back(20);
vect.push_back(30);
vector vect{ 10, 20, 30 };
int arr[] = { 10, 20, 30 };
int n = sizeof(arr) / sizeof(arr[0]);
vector vect(arr, arr + n);
vector vect1{ 10, 20, 30 };
vector vect2(vect1.begin(), vect1.end());