I want to get an unknown number of integers separated by space as user input. How can I store them in an array?
Asked
Active
Viewed 54 times
1 Answers
-1
You could keep changing the size of the array (since you don't know how big to make it). Or use a data structure (like a vector) designed to change size.

Scott Hunter
- 48,888
- 12
- 60
- 101
-
1In which case would you ever use your first suggestion? – Rotem Jul 06 '19 at 15:02
-
How can I stop the loop? As an example, if I know the number of inputs I can use a statement like this, while(i<=n){cin >> array[i]} – Lamudu Mohotti Jul 06 '19 at 15:04
-
@Rotem: If you were required to use an array. – Scott Hunter Jul 06 '19 at 22:22
-
@LamuduMohotti: That depends on the format of the input, and is a separate question from how to store them. – Scott Hunter Jul 06 '19 at 22:23