Hello all,
Happy new year !
I have a problem with fstream.
Here is my code:
fstream myfile ("users\\users.ini");
string line;
if (myfile.is_open()) {
while (! myfile.eof() && nick != line )
myfile >> line;
//HERE STARTS THE PROBLEM
//WRITE A NEW USER
if (line != nick) {
myfile << ios::app;
myfile << nick <<
"\n"
<<
"user=" << nick2 << "\n"
<<
"pass=" << pass << "\n"
<<
"mail=" << mail1 << "\n";
//HERE STOPS THE PROBLEM
sendmail(nick2, pass, mail1);
sprintf(e, notice, snick,
"Your account info has been sent to your e-mail address");
senddata(e);
}
else {
sprintf(e, notice, snick,
"Account name is taken, please try using another nickname");
senddata(e);
}
myfile.close();
}
It does only read, but doesn't write. If I use ifstream to open, then I close the file, then I reopen with ofstream and then close it, this way I can write in the file, but I would like avoiding opening and closing 2 times, so I am trying with fstream (which should be both open and close).
Thanks to anyone who can help.