Thread: reading data from vector question

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    26

    reading data from vector question

    I have a vector that is made up of structures. I'm wondering how to read the data from each structure that is stored in the vector. Thanks for any help in advance.

    Thanks, Rubiks14

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    nameofvector[index].memberofstruct

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Code:
    vector<myStruct>::const_iterator pos = myVector.begin();
    for(; pos != myVector.end(); ++pos)
    {
          cout<<pos->dataMember<<endl;
    }
    You should consider using a vector of pointers to your structs.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    26
    might sound dumb but what exactly does index represent?

    EDIT: nevermind i figured it out...i have no idea why i didn't think of that before though...i probly need to take a break
    Last edited by Rubiks14; 02-25-2006 at 08:56 PM.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> You should consider using a vector of pointers to your structs.

    Considering other options is not a bad idea, but storing struct instances directly should be the default. You would only store pointers if you had a specific reason (e.g. use of polymorphism or performance problems due to expensive copying). Pointers make the design more complicated so they should not be used unless necessary.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading large complicated data files
    By dodzy in forum C Programming
    Replies: 16
    Last Post: 05-17-2006, 04:57 PM
  2. accessing my com port, writing and reading data
    By shoobsie in forum C Programming
    Replies: 7
    Last Post: 09-16-2005, 03:29 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. reading data format into program
    By lambs4 in forum C Programming
    Replies: 1
    Last Post: 10-23-2003, 02:27 PM
  5. Binary data reading
    By jdinger in forum C++ Programming
    Replies: 3
    Last Post: 03-07-2002, 06:56 PM