Thread: Displaying Record

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Displaying Record

    Thanks!
    Last edited by cherries; 12-20-2007 at 03:52 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    4
    ??

    Sorry but I don't know how to use vector. Could you explain how? Thanks.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    4
    Which data must be hold in vector?

  7. #7
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    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

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    4
    i think i just solved the problem! thanks everyone!

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    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.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with binary file c++
    By lucky_mutani in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 09:24 AM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. behind and confused
    By steviecrawf in forum C Programming
    Replies: 1
    Last Post: 11-09-2001, 12:51 PM