stl map的用法
来源:互联网 发布:VB用迭代法求方程的根 编辑:程序博客网 时间:2024/05/22 01:59
#include<iostream>
#include<map>
#include<boost/format.hpp>
int main(int argc,char*argv[])
{
typedef std::map<int,std::string> t_map;
t_map T_map;
//insert:
int i=0;
std::string str;
for(;i<=10;i++)
{
str = (boost::format("string%d")%i).str();
if(T_map.insert(std::make_pair(i,str)).second==false)//已有键值对存在
#include<map>
#include<boost/format.hpp>
int main(int argc,char*argv[])
{
typedef std::map<int,std::string> t_map;
t_map T_map;
//insert:
int i=0;
std::string str;
for(;i<=10;i++)
{
str = (boost::format("string%d")%i).str();
if(T_map.insert(std::make_pair(i,str)).second==false)//已有键值对存在
std::cout<<"insert error"<<std::endl;
}
//delete find
T_map.erase(10);
t_map::iterator it = T_map.find(9);
if(it!=T_map.end())
T_map.erase(it);
//edit
T_map[8]="string_edit";
//bl
for(it=T_map.begin(); it!=T_map.end();++it)
{
std::cout<<"key:"<<it->first<<"value:"<<it->second<<std::endl;
}
//遍历并删除
for(it=T_map.begin(); it!=T_map.end();)
{
T_map.erase(it++);
}
std::cout<<"size of map:"<<T_map.size()<<std::endl;
return 0;
}
//delete find
T_map.erase(10);
t_map::iterator it = T_map.find(9);
if(it!=T_map.end())
T_map.erase(it);
//edit
T_map[8]="string_edit";
//bl
for(it=T_map.begin(); it!=T_map.end();++it)
{
std::cout<<"key:"<<it->first<<"value:"<<it->second<<std::endl;
}
//遍历并删除
for(it=T_map.begin(); it!=T_map.end();)
{
T_map.erase(it++);
}
std::cout<<"size of map:"<<T_map.size()<<std::endl;
return 0;
}
0 0
- STL的map用法
- STL的map用法
- STL的map用法
- stl--<map>的用法
- stl map的用法
- STL map的用法
- STL--- map的用法
- STL map的用法
- stl map的简单用法
- Map容器的用法(STL)
- Map容器的用法(STL)
- STL中map的用法
- STL中MAP的用法
- STL 中 map 的用法
- STL中map的用法
- Map容器的用法(STL)
- STL 中map的用法
- STL中 map的用法
- Java语言概述
- eclipse学习使用问题整理
- RBAC权限管理
- MySql锁表解表
- linux crontab 简单整理
- stl map的用法
- 奥巴马筹款网站的制作过程
- 关于android性能优化问题
- UICollectionView headerView footerView
- 0PE内置菜单解读(NB版) NB版0PE内置菜单解读
- java调用kettle向job(任务)和transformation(转换)传递参数实例
- 第一次接触ExpandableListvie这个控件
- RRAS实现windows azure站点到站点VPN
- android开源项目和框架