在 C++ 中搜索并插入具有 3 个元素的映射;
我需要有一个像这样的地图:
typedef std::map<int, float , char> Maptype ;
在此地图中插入和搜索对元素的语法是什么。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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 astd::pair
.你不能拥有三个元素。 STL
map
存储一个键值对。您需要决定要使用什么作为密钥。完成后,您可以将其他两个嵌套在单独的映射中并将其用作:为了插入映射,请使用
operator[]
或insert
成员功能。您可以使用find
成员函数进行搜索。此外,您还可以查看 Boost.Tuple。
You cannot have three elements. The STL
map
stores a key-value pair. You need to decide on what you are going to use as a key. Once done, you can probably nest the other two in a separate map and use it as:In order to insert in a map, use the
operator[]
or theinsert
member function. You can search for using thefind
member function.Additionally you can look at Boost.Tuple.
使用其中一个
或
哪个是正确的。
Use either
or
whichever is correct.