Thread: Accessing elements in a list

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    42

    Accessing elements in a list

    I am trying to access t1.name and t2.name that stored in the link_list, and I don't what to do at the for loop. Could someone please help me out? Thank you in advance.

    Code:
    struct T {std::string name; double unit;};
    
    list<T> link_list;
    
    T t1, t2;
    
    t1.name = "t1name";
    t2.name = "t2name";
    
    link_list.push_back(t1);
    link_list.push_back(t2);
    
    list<T>::iterator iter;
    
    for(iter=link_list.begin(); iter != end() ; ++iter)
    {
            cout << iter->???
    }

  2. #2
    Registered User
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    41
    Code:
    for(iter=link_list.begin(); iter != link_list.end() ; ++iter)
    {
            cout << iter->name;
    }

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    42
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 12:30 PM
  2. Conflicting types of typedef error
    By advocation in forum C++ Programming
    Replies: 4
    Last Post: 03-22-2005, 06:26 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM