1 Star 2 Fork 1

Huoty/cppstudy

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_unordered_map.cpp 822 Bytes
一键复制 编辑 原始数据 按行查看 历史
Huoty 提交于 2024-12-08 23:34 +08:00 . update at 20241208233432
/*
* Copyright (c) JoinQuant Development Team
* Author: Huayong Kuang <kuanghuayong@joinquant.com>
*/
#include <iostream>
#include <unordered_map>
using namespace std;
typedef unordered_map<int, int> uo_map_t;
string check_key(uo_map_t m, int key)
{
// Key is not present
if (m.find(key) == m.end())
return "Not Present";
return "Present";
}
int main()
{
uo_map_t m;
// Initializing keys and mapped values
m[1] = 4;
m[2] = 6;
m[4] = 6;
// Keys to be checked
int check1 = 5, check2 = 4;
// Function call
cout << check1 << ": " << check_key(m, check1) << endl;
cout << check2 << ": " << check_key(m, check2) << endl;
int t = m[10];
cout << "try get value from map: " << t << endl;
int t2 = m.at(20);
cout << "at 20: " << t2 << endl;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/konghy/cppstudy.git
git@gitee.com:konghy/cppstudy.git
konghy
cppstudy
cppstudy
master

搜索帮助