i am trying to read the following information:
Carlingford,Epping,3
Epping,Marsfield,6.5
Marsfield,North Ryde,2.4
North Ryde,Epping,5
Carlingford,North Ryde, 3.5
Carlingford,Marsfield, 4.7
North Rocks,Epping,4.8
Carlingford,North Rocks,2.4
North Ryde,Ryde,2.1
so i will be able to store the information into a 2 strings and a float (obviously excluding the comma. eg:
string station1 = North Ryde
string station2 = Ryde
float distance = 2.1
this is what i have so far...
void readText (string fileName)
{
string station1;
string station2;
string distance;
ifstream infile;
infile.open(fileName.c_str());
if (!infile)
{
cout << " File not found";
}
while(!infile.eof()) // To get you all the lines.
{
getline(infile, station1, ',');
getline(infile, station2, ',');
getline(infile, distance);
cout << station1 << " ---> " << station2 << endl;
cout << "Distance = " << endl;
cout << endl;
}
infile.close();
}
and this is the output i am getting...
Enter filename : suburb.txt
Carlingford ---> Epping
Distance =
Epping ---> Marsfield
Distance =
Marsfield ---> North Ryde
Distance =
North Ryde ---> Epping
Distance =
Carlingford ---> North Ryde
Distance =
Carlingford ---> Marsfield
Distance =
North Rocks ---> Epping
Distance =
Carlingford ---> North Rocks
Distance =
North Ryde ---> Ryde
Distance =
---> Ryde
Distance =
Press any key to continue . . .
i am not really sure what to try next and have gone through dozens of different sample code, i am also unsure why i am getting the extra value at the end with no station1 value.
any help would be much appreciated!