I am trying to access a specific element out of a std::map with more than two elements. Here is an example:
std::map <int, CString, CString, CString> map;
//Initialise
map[0] = _T("stuff1"), _T("stuff2"), _T("stuff3");
//now if I just want to access stuff3 is it this:
CString str = map[0][2];
//or something more like this?
CString str = map[0]. ???
Any help would be great thanks.
edit: Thanks sorry about that, first time using maps, I was wondering why I couldn’t find any information on std::map ‘s with more elements inside.
Have you tried to compile this? It shouldn’t.
You can create only a map with exactly 1 key and 1 value for each element.
But the value can be compound, so you can write
and access elements like
map[somekey].v3;To insert a value in such a map, you’ll have to write
Or you may create a helper function (i.e.
void addToMap(std::map <int, ValueType> &map, CSting const& v1, CString const& v2, CString const& v3)), which will fill your map in a more convenient way.