I want to read mulitple variables from a file and store them in a object, but its not working.
File example:
De vedettn
Wout Wouters
14 7 2005
Code that i wrote:
string naam, leider;
int dag, maand, jaar;
ifstream myfile ("file_ploeg.txt");
if (myfile.is_open())
{
cout << "Entering file" << endl;
while ( myfile.good() )
{
cout << "Entering while" << endl;
getline (myfile,naam);
cin >> dag >> maand >> jaar;
getline (myfile,leider);
}
Datum* datumOBploeg = new Datum(dag,maand,jaar);
Wielerploeg* wielerploegOB = new Wielerploeg(naam, *datumOBploeg,leider);
myfile.close();
cout << "\n";
return wielerploegOB;
}
Looks like you’re reading your lines out of order (at least according to your example file).
Should be:
Also, if I were you, I’d review the rest of the code in your function and make sure you’re not abusing pointers.