Read from textfile and store in multidimensional vectors

I am attempting to use multidimensional vectors to store the following dataset which is stored in a text file.
I am looking for suggestions on how to design the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
                                                        END OF HEADER
 09  8 17  0  0  0.0000000  0  9G04G09G02G12G27G17G28G08G15
 -24389977.51348 -18989277.00846  21084492.8364   21084482.9104
        50.0004         38.5004
 -11717496.08247  -9063199.56145  21115595.1804   21115584.9614
        43.7504         32.2504
 -15815385.43247 -12311176.44145  22946135.3054   22946123.1524
        46.5004         31.5004
  -1552963.53346  -1163730.19142  24359328.8134   24359317.7734
        36.0004         16.7504
 -15195458.40147 -11823088.74846  21413063.5474   21413052.9184
        47.7504         36.0004
 -21572719.04547 -16797895.57545  21466436.0004   21466424.1414
        43.7504         34.7504
 -13531252.42747 -10525127.63144  22878039.7504   22878028.3014
        44.5004         28.0004
  -1073852.15045   -828492.95742  25038820.1414   25038809.8054
        35.7504         16.2504
    108661.16746    194209.78843  24308885.3284   24308876.6914
        39.5004         19.5004
 09  8 17  0  0 15.0000000  0  9G04G09G02G12G27G17G28G08G15



I am able to determine the number of rows of data by reading the line below. The first digit represents the number of rows.

9G04G09G02G12G27G17G28G08G15


Therefore i able to use the find() and substrc() functions, and convert it to an interger. This would establish one of boundaries of my for loop.
In this case there would be 9 rows of data.



This is the first row of data:


-24389977.51348 -18989277.00846 21084492.8364 21084482.9104
50.0004 38.5004


I need to store this in columns 1 to 6. Here lies one of my problems, if i use the getline function, how do i read the 2nd line.

Within the header which isn't given above, it states how many readings in a row. In this case, there is 6. If the readings are more than 4, it goes to another line.

Also, the characters are always a fixed number apart, therefor i count the characters to extract each value to put them in each column. Then use a for loop to repeat it to the other lines.
I am thinking about structuring my multi-dimensional vectors using the code below. It was suggested by ropez in the forum discussion http://www.cplusplus.com/forum/general/833/ .



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vector< vector<int> > vec;

for (int i = 0; i < 10; i++) {
    vec.push_back(vector<int>()); // Add an empty row
}

for (int j = 0; j < 20; j++) {
    for (int i = 0; i < vec.size(); i++) {
        vec[i].push_back(i * j); // Add column to all rows
    }

    }
}


I solved the problem using Data Structures and multi-dimensional vectors.

The code is for an Rinex Observation Reader.

The solution is long, if anyone in the future need assistance feel free to message me.
Topic archived. No new replies allowed.