简体   繁体   中英

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.

For example) x=-1 y=0 I would get a certain symbol '$'

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'

Any help will be much appreciated,

Thank you, Al

'-1' is a multi-character constant, with a value that's probably out of range for char . If you mean to use the values -1 and 0 , then remove the quotes.

For portability, if the values might be negative, you should use a type that's guaranteed to be signed (like int or signed char ). Otherwise, you might get a surprise if you change to a compiler that gives an unsigned char .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM