Hey nico
thanks for reply
yeah i wanted it to overwrite what i had in there already but it wasnt 
writing the new text just clearing it. and yeah the ios::app does work for 
appending i just checked it will be handy in the future. the problem was 
that i was using outfile for both reading and writing once i put it in 
separate functions it worked fine
thanks for your help


>From: "Nico Heinze" <[EMAIL PROTECTED]>
>Reply-To: [email protected]
>To: [email protected]
>Subject: [c-prog] Re: Writing to text files
>Date: Sun, 04 Mar 2007 21:49:30 -0000
>
>--- In [email protected], "glogic_1" <[EMAIL PROTECTED]> wrote:
> >
> > Hey all
> > Im having a problem writing to text files. I am able to read
> > from them no problem but just cant write to it.
> >
> > struct sScore {
> >         char cName[40];
> >         int score;
> > }TopTen[SCORES];
> >
> > fstream OutFile;
> > OutFile.open("HighScore.txt",ios::in);
> > if (OutFile){
> >      while (!OutFile.eof())
> >      {
> >             OutFile >> TopTen[iNumber].cName;
> >             OutFile >> TopTen[iNumber].score;
> >             iNumber++;
> >       }
> > }
> >
> > The above code works fine for taking in player name and
> > score no prob but the below code, when im sending an
> > amended topten back out to the txt, just clears the txt
> > file completely
> >
> > OutFile.open("HighScore.txt",ios::out);
><snip>
>
>Of course your code overwrites the existing text.
>
>Why?
>
>Because you open the text file in output mode; this means: forget
>about the existing content and rewrite the file from scratch.
>
>What you probably need (I am no C++ expert) is something like
>   OutFile .open( "HighScore.txt", ios::app);
>if you want to _append_ text to an existing file.
>
>I don't know for sure whether ios::app is correct; I just browsed
>through ios.h and found the constants in, out, and app there, so I
>hope it's correct.
>
>Regards,
>Nico
>

_________________________________________________________________
Don’t miss your chance to WIN 10 hours of private jet travel from Microsoft® 
Office Live http://clk.atdmt.com/MRT/go/mcrssaub0540002499mrt/direct/01/



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/hOt0.A/lOaOAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/c-prog/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/c-prog/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to