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

Pages: 1-

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:36

fseek(). NEXT!

Name: Anonymous 2010-11-20 18:37

So my question is where can I find some code tags and question marks.

Name: Anonymous 2010-11-20 18:40

>>3
Sorry, I don't post here a lot (it shows)
Also saging my own thread due to question answered

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.

Name: Anonymous 2010-11-20 18:46

fopen("characters.txt", "a")

Name: Anonymous 2010-11-20 18:50

>>5
I actually learned scheme last year and still have to write my current software project in scheme (although it's called racket now, don't really see why). I'm also learning assembly (for the i386) and C this year.

Half of my first year was actually based on structure and interpretation, still got it lying around my desk.

I'll google more the next time, I spend some time searching the c++ resources network.

>>6

Thanks

Name: Anonymous 2010-11-20 18:55

You would try The D Programming Language, if you need something Sepples-like that doesn't suck.
But listen to >>5

Name: Anonymous 2010-11-20 18:57

>>8

Can't really choose my own language, I'm studying it at my university, they decided that we should learn an industry popular language in our second year

Name: Anonymous 2010-11-20 19:09

>>9
Implement an interpreter for anything else in it, and embed actual programs in it.

Name: Anonymous 2010-11-21 19:30

>>7
Well, here we have it /prog/; someone who already knows STHICKP, yet cannot program. I hereby put forward that we no longer tell people to read said aforementioned book; it is clearly ineffective!

Name: Anonymous 2010-12-09 8:59

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