Thread: array of structures

  1. #1
    Registered User
    Join Date
    Jul 2004

    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)

     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
    You want an array of vectors containing strings.
    vector<string> nameListArray[20];

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Or ...
    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:
    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, 05:54 PM
  5. Need serious help on array of structures
    By cwd in forum C Programming
    Replies: 2
    Last Post: 11-11-2001, 03:39 PM