trouble with processing input

Hello.

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().

thanks.
while (cin >> x;) {
I don't think that that is valid.
To get a certain amount of integers, try:
1
2
3
int myarray[10];
for (int c = 0; c<=9; c++){
    cin >> myarray[c];}
Last edited on
Ye but I don't know how many there will be. For example if N = 5 and K = 5, the input can look like this:

54 45 11 10
12 546 12 45 12
12 12
122
12 123 12
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.
I get it from a system, not from a user.
Use a vector to store the data. If lines are important, then use getline() to get each line separately, then read those lines into vectors.
Topic archived. No new replies allowed.