I have map<string,list<string> > wMap; and to insert new values I use wMap[word].push_back(file); which works but adds the same value twice even is its already in there. I am not sure how to access the values in the list individually. Several things that I would like to accomplish are testing to see if the value is already in the list, ie for the key a i can have values 1,2,3 but cannot have 1,2,2,3. If the value is already there dont add a second. Another is taking the values from the list and pushing them the the back of a vector. Please help I dont know where else to go.
Yea I understand and I need a key to be able to have more than one value that's why I chose a list. But is there no was to access that list within the map in-order to compare to see if the value is already there and other functions?
wMap[key] gives you a reference to the list. You're already accessing it when you push_back.
1 2 3
list<string>& ref = wMap[key];
// here, ref is your list... so can do whatever you want with it
Though if you want only unique elements in the list... consider using a set instead of a list. sets are the same idea with 3 differences:
1) faster searching for specific elements
2) DO NOT retain 'pushed in' order the same as lists do (ie: it's an ordered container, so values don't stay in the order you added them.. they get sorted)
3) Every entry is unique