R
Rene
Hello to all!
I am a newbee to C++, I did a beginners' course, and now I am stuck with a
strange problem.
I have written the function that is pasted downwards. The peculiar thing is
that when I sent the function the value "0", the .lst file is created
properly (the vector I am using/saving is made up of structs of one
AnsiString (using BCB) called "naam" and one int called "nummer", I guess
You'll get what they mean in English ;-)). When however I want to have the
file backupped first to a .bak file, I sent it "1". In that case, the .bak
file is created properly. But the .lst file not anymore, it remains empty. I
have already stepped throught the code and the loop is executed in the
normal way in the second part of the function when I enable the backup.
However, the file on disk remains empty. Next time I call the function, the
..bak file is "filled" again but with emptiness which in itself is logical,
there is nothing in the .lst file to be copied. However, when I call the
function with "0" again, the .lst file again is filled like it is supposed
to.
I just can't figure out why the .lst file is not filled after the part of
the function that makes the backup has been executed. BTW I am not using the
files anywhere else in the program.
Thank You very much in advance for any help!
Yours sincerely,
Rene
P.S. "Bestand" is Dutch for "file".
void TForm1::slaOp(bool backup)
{
fstream uitvoerBestand;
fstream backupBestand;
char letter;
if (backup)
{
uitvoerBestand.open("Quizdata.lst", ios::in);
backupBestand.open("Quizdata.bak", ios:ut);
uitvoerBestand.get(letter);
while (!uitvoerBestand.eof())
{
backupBestand.put(letter);
uitvoerBestand.get(letter);
}
backupBestand.put(letter);
backupBestand.close();
uitvoerBestand.close();
}
uitvoerBestand.open("Quizdata.lst", ios:ut);
for (int teller = 0; teller < aantalDeelnemers; teller++)
{
uitvoerBestand << setfill('0') << setw(3) << setprecision(3);
uitvoerBestand << deelnemerLijst[teller].nummer;
uitvoerBestand << deelnemerLijst[teller].naam.c_str();
if (teller < aantalDeelnemers - 1)
{
uitvoerBestand << endl;
}
}
uitvoerBestand.close();
}
I am a newbee to C++, I did a beginners' course, and now I am stuck with a
strange problem.
I have written the function that is pasted downwards. The peculiar thing is
that when I sent the function the value "0", the .lst file is created
properly (the vector I am using/saving is made up of structs of one
AnsiString (using BCB) called "naam" and one int called "nummer", I guess
You'll get what they mean in English ;-)). When however I want to have the
file backupped first to a .bak file, I sent it "1". In that case, the .bak
file is created properly. But the .lst file not anymore, it remains empty. I
have already stepped throught the code and the loop is executed in the
normal way in the second part of the function when I enable the backup.
However, the file on disk remains empty. Next time I call the function, the
..bak file is "filled" again but with emptiness which in itself is logical,
there is nothing in the .lst file to be copied. However, when I call the
function with "0" again, the .lst file again is filled like it is supposed
to.
I just can't figure out why the .lst file is not filled after the part of
the function that makes the backup has been executed. BTW I am not using the
files anywhere else in the program.
Thank You very much in advance for any help!
Yours sincerely,
Rene
P.S. "Bestand" is Dutch for "file".
void TForm1::slaOp(bool backup)
{
fstream uitvoerBestand;
fstream backupBestand;
char letter;
if (backup)
{
uitvoerBestand.open("Quizdata.lst", ios::in);
backupBestand.open("Quizdata.bak", ios:ut);
uitvoerBestand.get(letter);
while (!uitvoerBestand.eof())
{
backupBestand.put(letter);
uitvoerBestand.get(letter);
}
backupBestand.put(letter);
backupBestand.close();
uitvoerBestand.close();
}
uitvoerBestand.open("Quizdata.lst", ios:ut);
for (int teller = 0; teller < aantalDeelnemers; teller++)
{
uitvoerBestand << setfill('0') << setw(3) << setprecision(3);
uitvoerBestand << deelnemerLijst[teller].nummer;
uitvoerBestand << deelnemerLijst[teller].naam.c_str();
if (teller < aantalDeelnemers - 1)
{
uitvoerBestand << endl;
}
}
uitvoerBestand.close();
}