Mhm, so, the problem I'm having here is that, once the "while (!boatList.eof())" cycle reads the first line (EDIT: I meant, how should I put it, the first "segment"), it goes on infinite (?) loop reading the other one.
AX 777 Valtis 0 4 500 2007 5.5 -1 50.2 6
FZ 138 0 4 500 2007 5.5 -1 50.2 6
FZ 138 0 4 500 2007 5.5 -1 50.2 6
FZ 138 0 4 500 2007 5.5 -1 50.2 6
FZ 138 0 4 500 2007 5.5 -1 50.2 6
Notice how, when on infinite loop, only the regNumber changes (and only once), type being omitted completely, and everything else after that is identical to the first one. (Also, there is that strange space before regNumber value)
The code:
Boats loadBoatsFromFile(Boats boats)
{
int id;
string regNumber;
string type;
int maxPeople;
int maxWeight;
int yearMade;
double hourPrice;
int rentedByClient;
double moneyEarned;
int timesRented;
ifstream boatList ("boats.txt");
while (!boatList.eof())
{
getline (boatList, regNumber);
getline (boatList, type);
boatList >> id
>> maxPeople
>> maxWeight
>> yearMade
>> hourPrice
>> rentedByClient
>> moneyEarned
>> timesRented;
cout << regNumber << " "
<< type << " "
<< id << " "
<< maxPeople << " "
<< maxWeight << " "
<< yearMade << " "
<< hourPrice << " "
<< rentedByClient << " "
<< moneyEarned << " "
<< timesRented << endl;
if (!boatList.eof()) boats.push_back(createBoat(id, regNumber, type, maxPeople, maxWeight, yearMade, hourPrice, rentedByClient, moneyEarned, timesRented));
}
boatList.close();
return boats;
}
File contents:
AX 777
Valtis
0 4 500 2007 5.5 -1 50.2 6
FZ 138
Baidare
1 2 230 2008 5 -1 20 4
I have another function doing the same thing without getline's, which works as it should, also, I've managed to get around this problem myself by adding another getline at the end of the cycle, but I still want to figure out as to what exactly is wrong here.
I take it, it doesn't jump to another line for some reason, and I'd like to know why as I can't figure it out myself. (=_=)" Thanks in advance. :)