LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++, getting a value from a list (https://www.linuxquestions.org/questions/programming-9/c-getting-a-value-from-a-list-401504/)

YaK. 01-10-2006 03:26 AM

C++, getting a value from a list
 
Hello,

I know that with maps and vectors it's possible to get all the values saved in them with the [] operator. In lists it's not possible to get the values like this because I think a list has no random acces, but it must be possible to get all values by iterating. If I have an iterator i pointing to a position of the list how can I get the value saved at this position?

Thx for help

spooon 01-10-2006 03:49 AM

Use * to dereference an iterator: *iter

for example:
Code:

list<string> foo;
for (list<string>::iterator iter = foo.begin(); iter != foo.end(); iter++) {
  cout << *iter << endl;
}

in the above example *iter is a string

YaK. 01-10-2006 04:01 AM

ah, thanks a lot :)


All times are GMT -5. The time now is 05:00 PM.