array of structures

This is a discussion on array of structures within the C++ Programming forums, part of the General Programming Boards category; help, anyone??? i have a linked list containing strings (names), but what i need is an array of linked lists. ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    9

    array of structures

    help, anyone???

    i have a linked list containing strings (names), but what i need is an array of linked lists. i know that the array would have max of 20 elements (0-1)

    Code:
     vector <string> nameList(20);
    gives me one list of 20 elements, but i need 20 lists of x elements.

    how could i go about this??

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    You want an array of vectors containing strings.
    Code:
    vector<string> nameListArray[20];
    gg

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Or ...
    Code:
    std::vector<std::list<std::string> > nameListArray(20);
    That should create a vector (array) of 20 empty lists that can hold strings. To add a string to a list, just push it back onto the list at the appropriate index. For example, this code adds a string to the fifth list in the array:
    Code:
    nameListArray[4].push_back("Mayce Edward");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  2. filling an array of structures?
    By voodoo3182 in forum C Programming
    Replies: 9
    Last Post: 08-06-2005, 05:29 PM
  3. Array of Structures: Sorting
    By Drainy in forum C Programming
    Replies: 3
    Last Post: 04-13-2005, 09:55 AM
  4. Filling an Array of Structures
    By Zildjian in forum C Programming
    Replies: 5
    Last Post: 11-12-2003, 04:54 PM
  5. Need serious help on array of structures
    By cwd in forum C Programming
    Replies: 2
    Last Post: 11-11-2001, 02:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21