1、代码

 #include <map>
#include <string>
#include <stdio.h>
#include <vector>
#include <stdlib.h> using namespace std; class A
{
public:
int m_iX; public :
A();
A(int i);
~A();
}; A::A()
{
} A::A(int i)
{
m_iX = i;
} A::~A()
{
} typedef map<string, A *> MapA; void dumpMap(MapA & xMapA)
{
for(MapA::iterator pA = xMapA.begin(); pA != xMapA.end(); pA++)
{
printf("index : %s , value : %3d\n", pA->first.c_str(), pA->second->m_iX);
}
printf("-----------------------------------\n");
} int testOne()
{
printf("%s %d %s()\n", __FILE__, __LINE__, __func__); MapA xMapA; for(int i = ; i < ; i++)
{
A * a = new A(i);
char szIndex[] = {};
snprintf(szIndex, sizeof(szIndex), "%03d", i);
string strIndex = szIndex;
xMapA.insert(make_pair(strIndex, a));
}
dumpMap(xMapA);
printf("map size : %d\n", xMapA.size());
for(int i = ; i < ; i+=)
{
A * a = new A(i);
char szIndex[] = {};
snprintf(szIndex, sizeof(szIndex), "%03d", i);
string strIndex = szIndex;
MapA::iterator ppA = xMapA.find(strIndex);
if(ppA == xMapA.end())
{
printf("can not find : [%s]\n", strIndex.c_str());
continue;
}
xMapA.erase(ppA);
}
dumpMap(xMapA); printf("map size : %d\n", xMapA.size()); return ;
} int main(int argc, char * argv[])
{
testOne();
return ;
}

2、执行结果

./test-map
test-map.cpp testOne()
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
-----------------------------------
hash size :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
index : , value :
-----------------------------------
hash size :
over

最新文章

  1. ZBrush该如何通过结合KeyShot制作逼真玉佩
  2. 基于DDD的.NET开发框架 - ABP分层设计
  3. 适用于Magento的最合适的.htaccess写法
  4. C# winform程序怎么打包成安装项目(图解)
  5. 重拾C,一天一点点_11
  6. 【BZOJ】【2661】【Beijing WC2012】连连看
  7. CreateProcessWithLogonW(好像可以指定进程的上下文环境)
  8. hdu1233(最小生成树)
  9. 学习javascript基础知识系列第二节 - this用法
  10. 浅谈SharePoint 2013 站点模板开发 转载自http://www.cnblogs.com/jianyus/p/3511550.html
  11. PHP读取大文本文件并处理数据的思路
  12. PHP类自动加载技术
  13. cf A Simple Task---线段树
  14. .NET 使用 Azure Blob 存储图片或文件
  15. logging模块使用
  16. 基于matplotlib的数据可视化 - 热图imshow
  17. Solr相似度算法一:DefaultSimilarity(基于TF-IDF的默认相似度算法)
  18. 一头扎进 Java IO中-------java IO文件
  19. $Python技巧大全
  20. window server 搭建git服务器

热门文章

  1. TFS和VSS的简单对比
  2. 43. 动态规划求解n个骰子的点数和出现概率(或次数)[Print sum S probability of N dices]
  3. 22.整数二进制表示中1的个数[Get1BitCount]
  4. Solr5.3.1通过copyField设置多个field(字段)同时检索
  5. mysql show
  6. [Android Pro] fragment中嵌套viewpager,vierpager中有多个fragment,不显示
  7. EZ的间谍网络(codevs 4093)
  8. LinuxC语言读取文件,分割字符串,存入链表,放入另一个文件
  9. iOS开发网络篇—网络请求(HTTP协议)小结(转)
  10. Codeforces Round #360 (Div. 2) E. The Values You Can Make DP