![]() |
|
#1
|
||||
|
||||
inputing into filesHello,
Here is my question. I have a program where I have 2 functions. The first function (main) gathers two inputs of type string. I also remove the origional file so as to get rid of any left over text. The other function is able to take one string at a time and place it into a file. Now the problem is when I run the program and I open up the file, only the last string is in the file, and not both. Here is the code. CPP / C++ / C Code:
I understand that I could make f1 just take 2 strings but I need to do it this way. Any ideas? Thanks, Ronald __________________
This message is a natural product made from recycled electrons. The slight variations in spelling and grammar enhance its individual character and beauty and in no way are to be considered flaws or defects. |
|
#2
|
|||
|
|||
|
The f1() function is reopening the file each time, but the file pointer is at the beginning of the file by default, so it's overwriting what's there each time you write to it.
You can set it up to append data to the end by adding ios::app to the open() function, like so: CPP / C++ / C Code:
However you are wasting time reopening a file each time you wish to write to it - unless you're worried about file locking - so I'd suggest you leave it open as long as you need it. GF |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gxx linker accepts only 7 object files | danielxs66 | C++ Forum | 1 | 12-Dec-2003 10:27 |
| Opening files with a twist, C++ | calculus87 | C++ Forum | 2 | 26-Sep-2003 15:41 |
| [Linux] How to upgrade an rpm with source files? | JdS | Computer Software Forum - Linux | 2 | 18-Jun-2003 10:17 |
| Dedicated to JDS who does not like flash files | jrobbio | Open Discussion Forum | 9 | 15-Feb-2003 04:24 |
| publishing Drirector/Shockwave files ...? | darrin | Web Design Forum | 1 | 04-Oct-2002 18:21 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The