This is what I have done to read integers with std::cin
and store them in a vector:
int number;
vectorivec;
while (cin>>number)
{
Please find a simple solution to your problem, let me know if you see any issue with this solution.
#include
#include
using namespace std;
int main()
{
vector va;
int x;
while ( cin >> x ) {
va.push_back(x);
if ( cin.get() == '\n' ) break;
}
//Vector output
for ( int i = 0; i < va.size(); i++ ) {
cout << va[i] <<" ";
}
return 0;
}