Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ text output file

Name: Anonymous 2010-11-20 18:31

Hey /prog/, I'm learning C++ this year and I need to output a textfile for one of my tasks, to do this, I use this code:

void write_file (string race, int str, int con, int dex, int cha)
{
    fstream char_list ("characters.txt");
    char_list.open("characters.txt");
    char_list << race << "\t"
    << str << "\t"
    << con << "\t"
    << dex << "\t"
    << cha << "\n";
    char_list.close();
}

However, whenever I run the code, it overwrites the file with the new text. So my question is if there is any way to keep the previous contents of the file without manually picking up the text and inserting it after the new bit.

Name: Anonymous 2010-11-20 18:44

Well, at least he's polite. Here, I'll even help you: Sepples (C++) is a terrible language and you should start avoiding it immediately. Learn Scheme (using a book called Structure And Interpretation of Computer Programs) or at least Python. If you want to learn a low-level language, learn C and/or assembly; they're both good for giving you an idea of what's going on. Last but not least, read the fucking manuals and APIs. Spend at least one hour Googling intelligently before creating a post anywhere about your question. Someday you may become a good programmer, young padawan.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List