[英]Insert pair values of characters in an unordered map within the key value
I have been trying to create an unordered map that takes in (x, y) values as the key to look for its corresponding value. 我一直在尝试创建一个无序映射,它将(x,y)值作为查找其相应值的键。
For example) x=-1 y=0 I would get a certain symbol '$' 例如)x = -1 y = 0我会得到一个符号'$'
I have created the following unordered map: 我创建了以下无序映射:
static boost::unordered_map<pair<char, char>, char> map;
But I am having problems when I try to insert values into the map doing the following: 但是当我尝试将值插入到地图中时,我遇到了以下问题:
map.insert({ { '-1', '0' }, '$' });
It doesn't seem like I am getting a correct map. 我似乎没有得到正确的地图。
Whenever I do the following within the lookup of the map I get this: 每当我在地图查找中执行以下操作时,我都会得到:
char temp = map[{'-1','0'}];
temp = '0' temp ='0'
Any help will be much appreciated, 任何帮助都感激不尽,
Thank you, Al 谢谢,Al
'-1'
is a multi-character constant, with a value that's probably out of range for char
. '-1'
是一个多字符常量,其值可能超出char
的范围。 If you mean to use the values -1
and 0
, then remove the quotes. 如果您要使用值
-1
和0
,则删除引号。
For portability, if the values might be negative, you should use a type that's guaranteed to be signed (like int
or signed char
). 对于可移植性,如果值可能为负,则应使用保证签名的类型(如
int
或signed char
)。 Otherwise, you might get a surprise if you change to a compiler that gives an unsigned char
. 否则,如果您更改为提供unsigned
char
的编译器,您可能会感到惊讶。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.