Bonjour,
Je suis en train de faire un programme qui lit des informations dans un fichier, mais je ne comprends pas, il me prend 2 fois le dernier élément.
Merci de votre aide

Voici le fichier:
Milk
2.5
3.4
456
Butter
1.5
2.5
123
PS : Le fichier s'arrête juste derrière le 123.
Et voici le code
void ProductsManager::deserialize(char* fileName)
{
ifstream fileStream;
fileStream.open(fileName);
// If the file has been correctly opened
if(fileStream)
{
cout << "fichier opened" << endl;
getchar();
string name;
string buyingPrice;
string sellingPrice;
string quantity;
double dBuyingPrice, dSellingPrice;
int iQuantity;
// For each product
while(!fileStream.eof())
{
getline(fileStream, name);
getline(fileStream, buyingPrice);
getline(fileStream, sellingPrice);
getline(fileStream, quantity);
stringstream(buyingPrice) >> dBuyingPrice;
stringstream(sellingPrice) >> dSellingPrice;
stringstream(quantity) >> iQuantity;
cout << "dBuyingPrice : " << dBuyingPrice << endl;
Product temp(name, dBuyingPrice, dSellingPrice, iQuantity);
this->push_front(temp);
getchar();getchar();
}
fileStream.close();
}
else
{
// the file has not been opened correctly
throw "The file has not been opened correctly";
}
}
-----------------------------------------------------------------------------------
http://www.mesdevoirs.net -- Corrections de devoirs de mathématiques en ligne