Not sure how to read my data

I have the following data in a file, which I wish to read in. My struggle is in reading the numbers that are more than 1 digit (if it were just a digit I know how to do that with get). My other problem is that I don't know how to work with the fact that a line may have anywhere from 4 entries up to 9 entries. I have been told that vectors might be useful, but am seriously struggling to figure them out.

Here is what the data looks like:


1 6 2 3 4 5 6 7 2
2 6 3 1 7 8 9 10 3
3 6 4 1 2 10 11 12 4
4 6 5 1 3 12 13 14 5
5 6 6 1 4 14 15 16 6
6 6 7 1 5 16 17 18 7
7 6 8 2 1 6 18 19 8
8 3 9 2 7 19
9 3 20 10 2 8
10 6 11 3 2 9 20 21 11
11 3 12 3 10 21
12 3 13 4 3 11
13 2 14 4 12
14 3 15 5 4 13
15 3 23 16 5 14
16 6 17 6 5 15 23 24 17
17 3 18 6 16 24
18 3 19 7 6 17
19 2 8 7 18
20 3 22 21 10 9
21 3 11 10 20 22
22 1 21 20
23 3 25 24 16 15
24 3 17 16 23 25
25 1 24 23

I know how many lines I will need to read in, but not how to get the actual lines read in. I am trying to do this with generality as I will have more files with different data.

Thanks for any help!
To some extent, how you would read the data depends on what its meaning is, and what you will do with it afterwards.

For example, to read all the integers from the file you could do this:
1
2
3
4
5
6
    std::ifstream input("data.txt");
    int n;
    while (input >> n)
    {
        std::cout << n << '\n';
    }


Alternatively, to read all the lines from the file, do this:
1
2
3
4
5
    std::string line;
    while (getline(input, line))
    {
        std::cout << line << '\n';
    }


Note, in the latter case, you could use a stringstream to extract the integers from the line - if that's what you need to do.

So the question is - what are the requirements - what needs to be done?
Topic archived. No new replies allowed.