1.源码实现
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<int, string> mapStudent;
map<int, string>::iterator it;
mapStudent.insert(pair<int, string>(1, "student one"));
mapStudent.insert(pair<int, string>(2, "student two"));
mapStudent.insert(pair<int, string>(3, "student three"));
it = mapStudent.find(2);
if(it != mapStudent.end())
{
cout << "Find, the value is " << it->second << endl;
}
else
{
cout << "Do not find" << endl;
}
return 0;
}
2.编译源码
$ g++ -o example example.cpp
3.运行及其结果
$ ./example
Find, the value is student two
网友评论