Welcome to RenEvo Sign in | Join | Help
in
Home IRC Wiisis C&C FarCry Blogs Forums Photos Downloads

Problem with fstream

Last post 01-05-2007, 2:56 PM by Jary. 2 replies.
Sort Posts: Previous Next
  •  01-01-2007, 6:08 AM 570

    Problem with fstream

    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.

  •  01-02-2007, 1:44 PM 578 in reply to 570

    Re: Problem with fstream

    When you open your file you need to specify that you are going to write to it. Try opening your file like this:

     fstream myfile("users\\users.ini", ios::out | ios::app);
     

  •  01-05-2007, 2:56 PM 601 in reply to 578

    Re: Problem with fstream

    Thanks but wasn't that. It is already implied in fstream. I had to do myfile.clear() to clear the data that was left from an empty line.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems