main.cpp
来自「《C++ STL开发技术引导》配套光盘 聆听大师级的指点」· C++ 代码 · 共 21 行
CPP
21 行
#include <hash_map>
#include <iostream>
int main(void){
using namespace std;
//创建hash_map容器对象hm
hash_map<const char*, float> hm;
//插入元素(水果名,单价),水果名为键值,单价为映照数据
hm["apple"]=3.6f;
hm["orange"]=3.2f;
hm["banana"]=1.8f;
hm["pear"]=2.3f;
hm["lichee"]=6.3f;
//打印元素
cout << "苹果价格: " << hm["apple"] << "元/斤\n";
cout << "桔子价格: " << hm["orange"] << "元/斤\n";
cout << "香蕉价格: " << hm["banana"] << "元/斤\n";
cout << "雪梨价格: " << hm["pear"] << "元/斤\n";
cout << "荔枝价格: " << hm["lichee"] << "元/斤\n";
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?