maptest.cpp
来自「C++STL map操作实例介绍。主要演示map的操作技巧和方法。」· C++ 代码 · 共 51 行
CPP
51 行
// mapTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <map>
#include <string>
#include <algorithm>
#include "iostream"
using namespace std;
typedef map<string,int> strMap;
int main(int argc, char* argv[])
{
strMap mapTest;
mapTest[string("jjhou")]=0;
mapTest[string("Jerry")]=1;
mapTest[string("jason")]=2;
pair<string,int>value(string("david"),3);
mapTest.insert(value);
strMap::iterator it=mapTest.begin();
for (;it!=mapTest.end();it++)
{
cout<<it->first<<' '<<it->second<<endl;
}
//实现元素的查找
strMap::iterator itel;
itel=mapTest.find(string("mchen"));
if (itel==mapTest.end())
{
cout<<"mchen not found"<<endl;
}
itel=mapTest.find(string("Jerry"));
if(itel!=mapTest.end())
{
cout<<"jerry found"<<endl;
}
itel->second=9;
cout<<"The jerry= "<<itel->second<<endl;
printf("Hello World!\n");
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?