You will have to keep track of where your previous record started [as you ALWAYS go either to the next or previous record - if you had to JUMP to a certain record forward, there would be no solution [other than read every record in between without displaying it].
You can get the current location of the current record by using tellg(). Store this in a list/vector or similar to track where you have been. As you go back, just use seekg() to move back to where you started reading last time.
You got the idea, but you will need to hold an array or vector [std::vector will be better because you don't have to worry about how large it needs to be].
Sorry but I don't know how to use vector. Could you explain how? Thanks.
I'm pretty sure there are LOTS of tutorials on how to use STL vector if you just search the web. In fact, there is a tutorial on www.cprogramming.com/tutorials, I'm pretty sure. Or if you have a C++ book nearby, I'm sure it will describe how to use vectors.
Simply put, a vector is a dynamically sizing array, so you can just add things to it, and when you want to find something back, it works like an array, using [index] to find element number "index".
Which data must be hold in vector?
A vector can hold any data type; ( int, double string ) Using an iterator to sort through a vector is an even more effiencent way of doing things.
for ( iter = list.begin(); iter != list.end(); ++iter )
std::cout << *iter << std::endl; // will show the list
Perhaps a little more precisely: a std::vector can properly contain objects of any data type that can be copied like the built-in types (i.e., types that are copy constructible and copy assignable with the usual semantics).
i think i just solved the problem! thanks everyone!
For future reference editing out your original post is a dumb thing to do. It takes away from the discussion and stops others from learning about what your original problem was. In the same way you've been helped, you should be willing to help others.
Please don't go round deleting all your posts when the problem is solved.
It makes the whole thread meaningless, and no one can benefit from it anymore.