在C ++中使用3个元素在地图中搜索和插入 [英] Searching and Inserting in a map with 3 elements in C++

查看:129
本文介绍了在C ++中使用3个元素在地图中搜索和插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个这样的地图:

I need to have a map like this :

typedef std::map<int, float , char> Maptype ;

在此地图中插入和搜索对的元素的语法是什么。

What is the syntax to insert and searching elements of pair in this map.

推荐答案

map 只能将一种键类型映射到一种数据类型。如果数据包含2个元素,请使用结构或 std :: pair

A map can only map one key type to one data type. If the data contains 2 elements, use a struct or a std::pair.

typedef std::map<int, std::pair<float, char> > Maptype;
...
Maptype m;
m[123] = std::make_pair(0.5f, 'c');
...
std::pair<float, char> val = m[245];
std::cout << "float: " << val.first << ", char: " << val.second << std::endl;

这篇关于在C ++中使用3个元素在地图中搜索和插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆