URGENT, strings extraction, getline, many spaces

This is about a college assignment. I have to extract the data from several lines and store them in suitable memory locations.
The lines are:


   1      334   John Steffensen         AUS   44.82
   2      500   Takeshi Fujiwara        ESA   46.92
   3      651   Dimítrios Régas         GRE   46.22


As you can notice, there are spaces at the start of every line and I need to use the getline function with a delimiter ' ' (white space).

Right now, all I have is:
 
getline(buffer, array[i], ' ');


Its all included in a loop but I am still not sure how to code that part. The current result I get is, the array fills up with white spaces.

Any help will be very appreciated :)

EDIT: Each complete line is already stored in a string variable.
Last edited on
What type of variable is array?

What do each of the "fields" in your file represent? For example the third field appears to be either the first name or the complete name.

Please post your current code.
Last edited on
Use stringstreams and the >> operator. It will automatically get rid of the white spaces.
Thanks a lot for all your replies.

Here is the complete txt file :

Data.txt

Heat 1
  Lane    num   Name                    Nat   Time
   1      334   John Steffensen         AUS   44.82
   2      500   Takeshi Fujiwara        ESA   46.92
   3      651   Dimítrios Régas         GRE   46.22
   4      352   Chris Brown             BAH   44.5
   5      1050  Rennyuow                TRI   45.7
   6      491   Arismendy Peguero       DOM   44.92
   7      897   Marcin Marciniszyn      POL   45.83
   8      626   Bastian Swillims        GER   45.44

 Heat 2
  Lane    num   Name                    Nat   Time
   1      351   Avard Moncur            BAH   45.27
   2      571   Brice Panel             FRA   46.02
   3      1166  Lewis Banda             ZIM   45.47
   4      915   Félix Martínez          PUR   46.86
   5      1151  Jeremy Wariner          USA   45.1
   6      684   David Gillick           IRL   45.35
   7      595   Martyn Rooney           GBR   45.47
   8      846   Hermán López            NCA   50.72




I have to read the text file and store each of the details in a structure (struct).

Above, I tried to use the getline function but it seems to be complicating things for me...any help? Maybe I should you sub strings?

And could you please elaborate on this? I am very inexperienced at coding :P



Use stringstreams and the >> operator. It will automatically get rid of the white spaces.

toum: I already extracted the entire line into a string. I can do this for all the lines one by one. I just need to know how to separate out the variables and store them in a string array or struct perhaps.
Last edited on
Topic archived. No new replies allowed.