C++ map problem
I have a small problem with a std::map. Whenever I run it in a loop the values only get updated, it doesn't insert new values for some reason.
I did a simple test:
The data it insert, while both keys and values are different, only get overwritten. In the end it will only input 1 key, not 3.
mymap.insert( pair<char*,char*>(m1,m2) )
Is there some way around this or is something wrong?
That's because you insert the same memory block (m1 and m2) multiple times. So you have a map of 3 entries, all of them pointing to the same block of memory, containing "value3" and "key3". You never inserted different memory blocks. Don't use char pointers. Use std::string. std::string will be copied automatically when you make a pair of it and insert it.