My problem is that I want to compare all the map elements with a_data and if they don't exist in the map, then I should insert a_data in the map. But instead the way I have it, it inserts a_Data after every comparison. I tried to add an if (iter == pointer_count.end()) before the insert() but it didn't work.

std::map has a built-in method, count, which accepts whatever type the key value for the map is. In your case, string*. Using this method you can check whether an element in map already exists with a specific key. Here's an example:

As the above post illustrates, your code would be a lot simpler if instead of pointers to std::string you'd store the std::string's themselves in the map.

Also, if data is an std::string, you still have operator== available to you, so you needn't use string::compare().

Anyway, you have a logic problem: you insert a_Data for every time you don't find data.
You want to insert a_Data only after you search all the map and never find it once.

123456789101112131415

for (Map_Type::iterator it = pointer_count.begin(); it != pointer_count.end(); ++it)
{
if (data == *(it->first)) // use less variables, less names to remember
{
a_Data = it->first;
++it->second;
break; // get out of the for loop
}
if (it+1 == pointer_count.end()) // we reached the end of the map without finding data
{
pointer_count[a_Data] = 1; // using map::operator[]break;
}
}

This is a quick and nasty solution for a nasty design, if I may say so.
If I were you, I'd try to simplify the overall design.