Hi, is there a way to go backwards while writting a file and correcting something on a previous line?
e.g
change:
1,1,0,4,1,0.5,0.75
2,1,0,4,1,5,10
to:
1,1,0,4,1,0.5,0.75
2,1,0,4,1,5,9
Thanks in advance! =o)
Hi, is there a way to go backwards while writting a file and correcting something on a previous line?
e.g
change:
1,1,0,4,1,0.5,0.75
2,1,0,4,1,5,10
to:
1,1,0,4,1,0.5,0.75
2,1,0,4,1,5,9
Thanks in advance! =o)
You can manipulate the "get file pointer" and "put file pointer" using fstream.seekg() and fstream.seekp(). You can also get the current location of each "file pointer" using fstream.tellg() and fstream.tellp().
Investigate these methods using your favorite C++ reference.
gg
Thanks Codeplug!!
umm... how do you store the position that tellp() returns? in the reference that I looked up, it just says "pos_type", what type is that exactly?
Also after I can get back to a certain position, is there a way to delete the stuff in front of it and put in new information?
Thanks
tell[g,p]() will return type streampos, which you can use as if it were a long.
There are no methods to delete or remove bytes in the middle of a file. You can replace existing bytes with new ones. For example: "123" => "1A3". If you want to do something like "123" => "13", you have to copy the file, ommitting the part you want to "delete". This goes the same for inserting data.
For deletion, you can avoid this by using a fixed width for each number. So for example, if the biggest number would occupy 4 spaces: "2 ,1 ,0 ,4 " => "2 ,1 ,0 ,4735". Having a fixed width also makes it easy to seek[g,p]() to the Nth number in the file.
Or you could use a binary file format.
gg