无符号char数组作为映射中的键(STL-C ++) [英] unsigned char array as key in a map (STL - C++)
问题描述
有一些与此相关的帖子,但我需要澄清一些内容. 我的程序中有一个结构,其字段之一是固定大小的数组(16).这是上述结构的简化示例:
There are some posts related to this, but I need to clarify something. I have a structure in my program, and one of its fields is a fixed-size array (16). This is a reduced example of the mentioned structure:
my_struct{
unsigned char my_field[16];
....
// some more fields here
};
我想将此字段用作地图的键,这是我的问题. -有没有办法使用类似
I want to use this field as a key for a map, and here is my question. - Is there a way to use a map like
map<unsigned char[16], some_defined_structure>
?否则,这将是以某种方式复制此char数组以适合之后要插入到地图中的数组或矢量结构的最佳方法吗?
? Otherwise, which would be the best way to somehow copy this char array to fit an array or vector structure to insert in the map afterwards?
推荐答案
unsigned char[16]
不适合用于键映射.不符合要求
但是std::array<unsigned char,16>
确实如此.
unsigned char[16]
is not a suitable type for key map. it does not meet the requirements
But std::array<unsigned char,16>
does.
这篇关于无符号char数组作为映射中的键(STL-C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!