zoukankan      html  css  js  c++  java
  • for loop cpp map

    map<char,int> first;
        first['a']=1;
        first['b']=2;
        first['c']=3;
        first['d']=4;
        first['e']=5;
    
        first['a']=11;      //overrite 1
        map<char,int>::iterator it;
        for(it=first.begin();it!=first.end();++it){
            cout<<it->first<<"="<<it->second<<endl;
        }
    
        typedef map<string,float> SFMap;
        SFMap second;
        second["abcdefg"]=3.1215926;
        second["sdfsdf"]=234234;
        second["sdfsdfdfdf"]=3219462;
        for(SFMap::iterator it=second.begin();it!=second.end();++it){
            cout<<it->first<<"="<<it->second<<endl;
        }
    
    /*****************************************/
    // constructing maps
    #include <iostream>
    #include <map>
    using namespace std;
    
    bool fncomp (char lhs, char rhs) {return lhs<rhs;}
    
    struct classcomp {
      bool operator() (const char& lhs, const char& rhs) const
      {return lhs<rhs;}
    };
    
    int main ()
    {
      map<char,int> first;
    
      first['a']=10;
      first['b']=30;
      first['c']=50;
      first['d']=70;
    
      map<char,int> second (first.begin(),first.end());
    
      map<char,int> third (second);
    
      map<char,int,classcomp> fourth;                 // class as Compare
    
      bool(*fn_pt)(char,char) = fncomp;
      map<char,int,bool(*)(char,char)> fifth (fn_pt); // function pointer as Compare
    
      return 0;
    }
    

      

  • 相关阅读:
    记录
    集合
    数据库一键退出脚本
    修改NLS_DATE_FORMAT的四种方式
    触发器
    (转)rlwrap真是一个好东西
    Windows常用技巧集锦
    UTL_FILE
    redis入门(03)redis的配置
    服务网关
  • 原文地址:https://www.cnblogs.com/wucg/p/2198265.html
Copyright © 2011-2022 走看看