std::map<uchar, int> m = {
std::make_pair('1', 346),
std::make_pair('2', 345),
std::make_pair('3', 436)
};
int main()
{
int i = 2;
uchar u = static_cast<uchar>(i);
int value = m[u];
std::cout << value;
}
Why this doesn't print '345'? If i set the value of 'u' to '2' it works fine.
Well, that's pretty much the same, isn't it? My question is how to convert 2 to '2'. Also, that integer in the example is not necessary at all, sorry. Here's my updated code.
1 2 3 4 5 6 7 8 9 10 11 12
std::map<uchar, int> m = {
{ '1', 346 },
{ '2', 345 },
{ '3', 436 }
};
int main()
{
uchar u = 2;
int value = m[u];
std::cout << value;
}