I want to know how I can accept multiple numbers on one line without exactly knowing in advance how many.
So for example if I have 1 2 3 4
as input I could use :
cin >> a >> b >> c >> d;
But if I don't know that the amount is 4 then I can't use that approach. What would be the right way to store the input into a vector?
Thanks in advance
You can read all input until the new line character in an object of type std::string and then extract numbers from this string and place them for example in a vector.
Here is a ready to use example
If you would input a line of numbers
then the program output from the vector will be
In this program you could substitute statement
for
main.cc
stdin
stdout
https://ideone.com/FHq4zi
Put it inside a loop: