I am new to the std::vector
class and was exploring ways of inserting elements into a vector as per the user request.
I've tried a loop to insert ten elements in a vector using the push_back()
member function, but my vector is only storing nine elements, if I start the indexing from zero.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v1;
for(int i = 0; i < 10; i++)
{
cin >> i;
v1.push_back(i);
}
}
I am using Visual Studio, and I am only able to insert nine elements into my vector. What can be the issue?