Hey guys! Please I need your help. I have two puzzling issues I am dealing with.
Issue 1: I am using a stringstream object in a block of my program that needs to be visited repeatedly depending on a user's selection from a menu. I want the contents of this stringstream object to be cleared any time control gets to this part of the program. I have tried the clear and flush functions to no avail. Any ideas?
Issue 2: I am reading data from a source text file that would be regularly changed during the course of program run. After the program run is over, I am supposed to save the results(which is basically the source text file AND all updates) in a destination file. This destination file would then serve as the source file when next the program is run. In other words, I want a scenario where my results overwrite the original contents of the source file; implying that my source and destination files are now one, pretty much. How can I do this?
Thx keskiverto, I have resolved the first issue. I am still having problems with the second one though. Your second suggestion is the trivial solution that first pops up in one's mind which I have tried. I opened the same file name as my source and destination in function main(); read the data into the program; however, I observed I could not access the 'read' contents of the file during program execution. It defies logic for this to happen; I hope it's not some oversight of mine somewhere else in the program. Is this the same approach you would have adopted?
It's still not working! What happens is I always find a blank file after the program has run. In essence, I cannot see any output showing the results. Consequently, the next run of the program has no source data to load!!
What is that
overwrite-mode-flag
stuff in your post? I'm guessing it's some file read/write mode; right?
I can see that your data is roughly a simple data type(a string); mine is a structured data type (a multi-data-member object) based off of a linked-list class and several other classes. I overloaded the stream insertion operator for two of the classes that are derived classes from the linked-list base class. However, the function tasked with printing to the file is a member function in one of the derived classes. Should this difference in data formats have any bearing, at all, on this read-and-write-same-file scheme I am seeking?