0

Problems reading data from a txt file C++

I'm trying to read some information from a txt file, and trying to store it in a list, the file has the following format: 1|mexico|canada|44.4 2|canada|china|11.1 Where the fileds are id, origen, destiny and weight. I have a method that it's trying to read each of them using getline, and trying to store it in a list, but when I store the data in my list and I try to show it, it shows random numbers. How can I solve it? The code it's here: https://code.sololearn.com/c4t0PLylYZPo/#cpp Line 96 I'm showing my list data, and line 125 you can find how I'm processing the data and store it into the list, but it doesn't work. Also inside the while (137) I'm trying to convert string to int and string to double, but I'm not sure if that's the correct way to do it. Please help!

16th Jan 2020, 9:59 PM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
3 Antworten
+ 1
Martin Taylor actually I found the solution calling 4 times getline, not the best way to solve the problem, but I did it, thx for the help, also I will consider to not put the list in the Paqueteria class.
17th Jan 2020, 12:50 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar