View Single Post
Old 11-07-2006, 01:10 AM   #1 (permalink)
Toshiro
True Techie
 
Join Date: Apr 2004
Posts: 115
Send a message via AIM to Toshiro Send a message via Yahoo to Toshiro
Default (C++) Overwriting file after taking input from it?

I'm making a super simple text-based adventure game to test out new things I learn in my introductory C++ class.

I'm trying to implement a simple save feature where the user hits 'R' (for Record) to save to a file called "savefile.txt". I got this working OK so far. It opens (or creates if not existing) the savefile.txt file, then outputs certain variable values to the file in a specific order. It then closes savefile.txt and continues the gameplay part.

When the program starts, the user can hit 'C' (for Continue) to read values from savefile.txt. It reads them into the same variables that were outputted in the save process, and in the same exact order as they were outputted to the file so that everything matches up. The gameplay part continues from here. If savefile.txt does not exist yet or doesn't have acceptable values in it, it will give an error message and terminate.

My problem is... If I choose "continue" and get input values from savefile.txt, I can't get it to overwrite savefile.txt when I save later. It just leaves savefile.txt blank and acts like everything worked fine (I have a "failed to open" error message in place that work fine when something else is wrong).

Also, if savefile.txt already exists and has data in it (from a previous save, for example), I can start a new game and overwrite it perfectly fine, with all correct new values. It just wont let me if I've already taken input from the file during the same run.

Any ideas as to what I might be doing wrong? I can post the code for the "save" and "continue" parts, if that will help.
__________________
Make: eMachines
OS: WinXP Pro
Mobo: Gigabyte 8VM533M-RZ
CPU: 2.2GHz Intel Celeron
Vid: Gigabyte NVidia MX 4000 (128 MB DDR, TV out)
Sound: onboard
RAM: 512MB DDR
HD: 40GB (1:3 partitioned), 34GB
Drives: DVD R/RW and 16x DVD-ROM
Browser: FireFox
ISP: AT&T/SBC Yahoo! DSL
Toshiro is offline   Reply With Quote