Thanks!
Thanks!
Last edited by cherries; 12-20-2007 at 03:52 AM.
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.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
??
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".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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.
Code:for ( iter = list.begin(); iter != list.end(); ++iter ) { std::cout << *iter << std::endl; // will show the list }
Double Helix STL
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).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.