I am having a problem and I am not sure why.
I want a map with char strings and whenever we try to add the same string the map should delete this string and increments the map element's value.
But for some reason it does not increment the element and adds the same string in the map.
I tried to keep the code example below small because I don't want to tire you without a reason.
I managed to make it work with std::string but now I wanted to train with C style strings also.
For some reason it worked when I had my str and map's first element as const char*
but the problem is that I don't want str to be const as in the rest of the program I want to append it.
each new'd array has a different memory address (they can only be reused after you delete[] some -- note that your "delete str;" is an error). Those memory addresses are what you're using as map keys. Thus, the pointer you get from new[] is never present in the map already, so you add it to the map every time.
Hey, thank you for your reply. Yes strings are much easier to handle, I am aware of that and I have already made it work with strings. But part of my task is to do it with chars. So do you have any good idea on how to do it? What do you mean by "Or provide a suitable comparison function to your map."?