zoukankan      html  css  js  c++  java
  • map的实际操作用并for_each遍历

    #include<iostream>
    #include<map>
    #include<algorithm>
    #include<string>
    using namespace std;
    void fun(map<int,int>::reference i)
    {
    	cout<<i.first<<' '<<i.second<<endl;
    }
    int main()
    {
    	map<int,string>student;//第一种方式创建 
    	map<int,int>num;//第二种方式创建 
    	student[1]="Alice";//用[] 插入元素 
    	student[2]="LiHua";
    	student.insert(map<int,string>::value_type(3,"Lily"));//用insert插入 
    	num[1]=1;
    	num[2]=2;
    	num.insert(map<int,int>::value_type(3,3));
    	for(map<int,string>::iterator i=student.begin();i!=student.end();i++)//用迭代器遍历 
    	cout<<i->first<<' '<<i->second<<endl;
    	for_each(num.begin(),num.end(),fun);//用for_each遍历 
    	map<int,string>::iterator j=student.find(1);//查找元素 
    	cout<<j->first<<' '<<j->second<<endl;
    	student.erase(student.begin());//删除元素
    	return 0;
    }
    

      

  • 相关阅读:
    rpc rmi http
    理解Global interpreter lock
    maven scope含义的说明
    实现图片缩放
    实现在edittext中任意插入图片
    上传图片或文件到服务器端
    onResume
    关于Context
    android bitmap compress
    saveFile()方法
  • 原文地址:https://www.cnblogs.com/spongeb0b/p/9147316.html
Copyright © 2011-2022 走看看