Wen said:
I'd try this, but it doens't work neither.
Regards,
Wen
void LeesMutatie(Client & MutatieRec, int& klantNr)
{
ifstream mutatie ("mutatie.csv");
Wen,
Its not the comma. The problem is that you are creating an ifstream instance
named "mutatie" every time you call LessMutatie(). Every time the first line
of this function is executed, you create an ifstream instance and open the
file "mutatie.csv". At this point, the rest of the function reads the file
from the very beginning.
In order to fix this, you will have to redesign your code to make sure that
you do not open the file on every call to LessMutatie(). For example, you
can try opening the file outside LessMutatie() and pass it a reference to
an ifstream instance:
// -------------------------------------------------------------------------
void LeesMutatie(ifstream& input_stream, Client & MutatieRec, int &klantNr);
int main()
{
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);
ifstream mutatie( "mutatie.csv" ) ;
LeesMutatie( mutatie, MutatieRec, klantNr);
while( MutatieRec.klantNr != HV )
{
cout << MutatieRec.klantNr << ":" << MutatieRec.soort << endl ;
LeesMutatie( mutatie, MutatieRec, klantNr);
}
cin.get();
}
void LeesMutatie(ifstream& mutatie, Client & MutatieRec, int &klantNr)
{
char puntkomma = ';';
if ( ! mutatie ) {
std::cout << "mutatie kaput." << endl ;
exit(1) ;
}
mutatie >> MutatieRec.klantNr >> puntkomma;
mutatie.getline(MutatieRec.soort, 2, ';');
mutatie.getline(MutatieRec.naam, 26, ';');
mutatie.getline(MutatieRec.adres, 26, ';');
mutatie.getline(MutatieRec.postcode,7, ';');
mutatie.getline(MutatieRec.plaats, 16, ';');
mutatie >> MutatieRec.bankNr >> puntkomma;
mutatie >> MutatieRec.giro >> puntkomma;
mutatie.getline(MutatieRec.mutcode, 2, ';');
mutatie.getline(MutatieRec.tariefAfspr, 2, ';');
if ( mutatie.eof() )
MutatieRec.klantNr = HV;
}
// -------------------------------------------------------------------------
There are other problems with the original LessMutatie() besides the
reopening of "mutatie.csv". But that is a separate issue that you will have
to figure out.