pr22015.cpp
来自「c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出」· C++ 代码 · 共 40 行
CPP
40 行
////////////////////////////////////////
// File Name: pr22015.cpp
////////////////////////////////////////
#include <iostream>
#include <map>
typedef std::map<int, char> MYMAP;
int main()
{
// Create the map object.
MYMAP charMap;
// Populate the map with values.
charMap[1] = 'A';
charMap[4] = 'D';
charMap[2] = 'B';
charMap[5] = 'E';
charMap[3] = 'C';
// Display the contents of the map.
std::cout << "Contents of map: " << std::endl;
MYMAP::iterator iter;
for (iter = charMap.begin();
iter != charMap.end(); iter++)
{
std::cout << (*iter).first << " --> ";
std::cout << (*iter).second << std::endl;
}
// Find the D.
MYMAP::iterator pos = charMap.find(4);
if (pos == charMap.end())
std::cout << "Element not found.";
else
std::cout << "Element found: " << (*pos).second;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?