[英]C++ Updating values in a unordered_map, where the data type of key-value pair is int-unordered_set
[英]Insert pair values of characters in an unordered map within the key value
我一直在嘗試創建一個無序映射,它將(x,y)值作為查找其相應值的鍵。
例如)x = -1 y = 0我會得到一個符號'$'
我創建了以下無序映射:
static boost::unordered_map<pair<char, char>, char> map;
但是當我嘗試將值插入到地圖中時,我遇到了以下問題:
map.insert({ { '-1', '0' }, '$' });
我似乎沒有得到正確的地圖。
每當我在地圖查找中執行以下操作時,我都會得到:
char temp = map[{'-1','0'}];
temp ='0'
任何幫助都感激不盡,
謝謝,Al
'-1'
是一個多字符常量,其值可能超出char
的范圍。 如果您要使用值-1
和0
,則刪除引號。
對於可移植性,如果值可能為負,則應使用保證簽名的類型(如int
或signed char
)。 否則,如果您更改為提供unsigned char
的編譯器,您可能會感到驚訝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.