比如Java中定义一个字符串、字符串映射:Map<String, String> map = new HashMap<String, String>();在C++中如何定义这样的映射呢?

解决方案 »

  1.   

    cmap
    A dictionary collection class that maps unique keys to values. 
    template< class KEY, class ARG_KEY, class VALUE, class ARG_VALUE >class CMap : public CObject
     Parameters
    KEY
    Class of the object used as the key to the map.ARG_KEY
    Data type used for KEY arguments; usually a reference to KEY.VALUE
    Class of the object stored in the map.ARG_VALUE
    Data type used for VALUE arguments; usually a reference to VALUE.
      

  2.   

    MFC 和 STL 里面都有
    #include <map>  //STL
    #include <afxtempl.h> //mfc
      

  3.   

    顺便问一下HashMap和Map有什么应用的区别呀,我发现都是想用哪个用哪个的……
      

  4.   


    // map::insert
    #include <iostream>
    #include <map>
    using namespace std;int main ()
    {
      map<char,int> mymap;
      map<char,int>::iterator it;
      pair<map<char,int>::iterator,bool> ret;  // first insert function version (single parameter):
      mymap.insert ( pair<char,int>('a',100) );
      mymap.insert ( pair<char,int>('z',200) );
      ret=mymap.insert (pair<char,int>('z',500) ); 
      if (ret.second==false)
      {
        cout << "element 'z' already existed";
        cout << " with a value of " << ret.first->second << endl;
      }  // second insert function version (with hint position):
      it=mymap.begin();
      mymap.insert (it, pair<char,int>('b',300));  // max efficiency inserting
      mymap.insert (it, pair<char,int>('c',400));  // no max efficiency inserting  // third insert function version (range insertion):
      map<char,int> anothermap;
      anothermap.insert(mymap.begin(),mymap.find('c'));  // showing contents:
      cout << "mymap contains:\n";
      for ( it=mymap.begin() ; it != mymap.end(); it++ )
        cout << (*it).first << " => " << (*it).second << endl;  cout << "anothermap contains:\n";
      for ( it=anothermap.begin() ; it != anothermap.end(); it++ )
        cout << (*it).first << " => " << (*it).second << endl;  return 0;
    }
      

  5.   

    stl map#include <map>
    using namespace std;