I am trying to read a .txt file and retrieve x and y coordinates, a city ID and cityname.
[1, 1]-3-Big_City
expected : x = 1, y = 1, city_ID = 3, city_name = Big_City
[2, 8]-2-Mid_City
expected : x = 2, y = 8, city_ID = 2, city_name = Mid_City
How do i read and store the x , y , city_ID and city_name
I have a while loop that can print out the whole line, but i do not know how to delimit using the unwanted symbols to get the required values
while(getline(inputFile, aLine))
{
getline(inputFile, aLine, '[');
x = aLine;
getline(inputFile, aLine, ',');
y = aLine;
//stuck here has getline 3rd parameter only accepts character and not string
getline(inputFile, aLine, ']-');
city_ID = aLine;
....
cout << x << " " << y << " " << city_ID
}
The output i get is also not what i expected. The first line would be missing and the others are not shown
Aucun commentaire:
Enregistrer un commentaire