| Chris Walton (17) | |||||
|
I'm having some trouble re-using a stringstream. What I mean by re-use, is that I've filled the stringstream up with file contents so that I don't have to read the file again later on. My program works pretty much like this:
Here is where my problem begins. When I allow the user to remove a line from the file, I try to use
where buffer is an empty string. However, when running the debugger I see that buffer is still empty after that line of code executes. It looks like I'm not moving the get pointer to the beginning of the stringstream to me, but I'm not sure why it isn't moving back. I'm trying to use as little memory as possible, so I'd rather not create a whole new stringstream that holds the exact same contents. Is there a way to do this? I can't post a whole lot of my code, but I'll try to clarify if my question/code isn't clear. | |||||
|
Last edited on
|
|||||
| Cubbi (1924) | ||
clear() first, then seekg()and of course, loop should be while(getline(...)) { ... }
How do you plan on removing something from the data held inside a stringstream? It may make more sense to read the file into a naked std::string instead, so that you can insert and erase. (after edit: oh.. I see, you're filling in a new stream, and then copying its contents over into the old one.) | ||
|
Last edited on
|
||
| Peter87 (3908) | |||
You have to clear the error flags before you can use seekg.
| |||
|
Last edited on
|
|||
| Chris Walton (17) | |
|
Ah, that was it. Thanks guys! Cubbi, that's what the newFC stringstream is for. Basically, the user types in a name to a text field and hits the Remove button. So I scan through the fileContents stringstream and clone it over into newFC. I skip over the name and it's associated values. Then, when the program terminates, I write the updated fileContents stringstream back to the disk. At least that's what it's supposed to do, I haven't gotten quite that far yet, haha. | |
|
|
|