Input an array without knowing the size in C++

Viewed 33

I have been trying to input an array without mentioning it's size. But in my VS Code IDE when I type in the array and hit the 'enter' button, the input doesn't terminate and keeps going on.

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    vector<int> inp;
    int temp;
    while (cin >> temp)
    {
        
        inp.push_back(temp);
    }

    for (auto x : inp)
    {
        cout << x;
    }
}

I've tried many methods but does'nt seem to work. I want the input loop to stop once I press 'enter'. This does not happen and keeps going until I type a character value;

0 Answers
Related