Let's say, that I have N lines of input where on each line are from 1 to K integers.
I have a bit trouble with reading this input correctly. I've tired:
1 2 3 4 5 6
for (int i = 0; i < N; i++) {
int x;
while (cin >> x) {
...
}
}
but it doesn't seem to work correctly. Can you pleas give me some tips on how to solve this? And I would like to read the integers directly into a integer variable. I mean I would like to avoid for example reading the whole line through for example getline().
Where do you get the input? If you get it from the user, simply ask them how many numbers they will input, then dynamically allocate an array of that size. Then get the input until the array is full.