Problem with looping through input

I am trying to read the input file:
ANTH
4.6934 4.74 5.77
BWLD
156.96 155.48 152.58
and store the inputs in 2 vectors (one for the string of letters and one for the floating point numbers). I can get the first two lines to be stored correctly but I am not sure how get the rest of the input.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
     vector<vector<float> tiles;
     vector<string> a;
     ifstream fin("input.txt");
     string line;
     int height, width;

     fin >> height;
     fin >> width;
     tiles.resize(height,vector<float>(width));

     while(getline(fin,line, ',')){

        vector<float> f;
        istringstream iss(line);

        float value = 0.0;
        string sn;
        
        int i = 0, j = 0;

        while(num_lines != sub){
           if(iss >> sn)
              a.push_back(sn);
        }    
        while(iss >> value){
           f.push_back(value);
           tiles[i][j++] = value;
           if (j == width){
              ++i;
              j = 0;
           }
       
     }

The outputs, respectively, for a[0] and tiles[0][0] - tiles[0][2] are:


ANTH
4.6934
4.74
5.77


I am not sure how to store the remaining 2 lines of the input in the same format, pushed back in the given vectors.
Last edited on
Why do you call getline with ','?
Topic archived. No new replies allowed.