欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

std::map 博客分类: c++  

程序员文章站 2024-03-18 00:03:22
...
  std::map<char,int> mymap;
  std::map<char, set<string> > mmap;

  mmap['a'].insert("hello");
  mmap['a'].insert("hello1");

  map<char, set<string> >::iterator iter = mmap.begin();
  for(;iter!=mmap.end();++iter){
   cout << iter->first << endl;
   set<string>::iterator itt = iter->second.begin();

   for (;itt != iter->second.end(); ++itt){
      cout << *itt << endl;
   }
  }

  // first insert function version (single parameter):
  mymap.insert ( std::pair<char,int>('a',100) );
  mymap.insert ( std::pair<char,int>('z',200) );

  std::pair<std::map<char,int>::iterator,bool> ret;
  ret = mymap.insert ( std::pair<char,int>('z',500) );
  if (ret.second==false) {
    std::cout << "element 'z' already existed";
    std::cout << " with a value of " << ret.first->second << '\n';
  }