![]() |
Help with fstream to a text file
Alright here is my dilemma. I have a program that is supposed to go out an look at a text file and determine if it has null information in one field. If it does have null information in that field another function needs to come back and overwrite the entire record as null. Fairly easy so far.
Now after that process I need to copy the non null contents of the data file to new file with the same name as the old file. Then delete the old file. This is the part that I don't understand. I guess I need to copy them to a temp file and then delete the old file but I don't know how to do this. All help is appreciated. |
Re: Help with fstream to a text file
Well you could copy it to a temp file and delete the old file, or just move it to the old filename, after all of it has been read in. Or you could move the old filename to a temporary location and go from there. What difference does it make to you?
|
Re: Help with fstream to a text file
Why bother to write to the original file when you're going to immediately throw away what you've written? Open a temp file. Read a record from the originial. If it has the null field, discard it, otherwise write it to the temp file. When you've finished, delete the original and rename the temp to the original name.
If you're saying you don't know how to delete and rename files, I would suggest a visit to the help files for your compiler and OS. |
Re: Help with fstream to a text file
I am feeling really dumb and need some help in a major way. I don't even know how I am supposed to delete the old file. What command would I use? Also I am now even having problems with the first part. What command can I use for the isNull() function to return the position of the record to be overwritten by the writeNullToFile() function?
|
Re: Help with fstream to a text file
Command? There's no command. You have to write it yourself.
What format are the text files in? |
Re: Help with fstream to a text file
just do a google for file io for your language
|
Re: Help with fstream to a text file
I'm guessing the language is C++ ;).
To the OP: You aren't paying attention to your responses. If you're going to indentify a record as being tossable by some field, overwrite the entire record with something that represents nulls, the read it back and throw it away, there's no point in overwriting it. Read the file record by record. You'll have to know your format in order to do that properly. Check the field that represents a discardable record. If the record is discardable, ignore it and read the next record. Otherwise, write the record to a temp file. Wash, rinse, repeat until the operation is done. Delete the original file (see 'remove'). Rename the temp file to the original file name (see rename). All this is relatively trivial (depending on your format). If it's news to you, you might be biting off more than you can chew without a little more practice. |
| All times are GMT -5. The time now is 3:24 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC