title: How to avoid duplicate values in maps using c++
body: <p>I am trying to write a program in C++ using maps...</p>
  <p>My goal is to avoid the same values repeated in maps.</p>
  <p>If the keys are same, we can use maps to avoid the duplicated keys. To allow duplicate keys, we use multimaps.</p>
  <p>In case the value is the same, how can we avoid that?</p>
  <p>The program which I have written allows duplicated values:</p>
  <pre><code>typedef std::map&lt;int, std::string&gt; MyMap;
  
  int main()
  {
      MyMap map;
      MyMap::iterator mpIter;
  
      int key;
      string value;
  
      int count;
      for(count = 0; count &lt; 3;count++)
      {
          cin &gt;&gt; key;
          cin &gt;&gt; value;
                 
          std::pair&lt;MyMap::iterator, bool&gt; res = map.insert(std::make_pair(key,value));
      }
  
      for (mpIter=map.begin(); mpIter != map.end(); ++mpIter)
           cout  &lt;&lt; &quot; &quot;  &lt;&lt; (*mpIter).second &lt;&lt; endl;
  }
  </code></pre>