【发布时间】:2019-01-17 12:10:26
【问题描述】:
我正在尝试对以下元素进行比较:
std::vector<std::array<uint8_t, 6> > _targets =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x11 }
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x22 }
};
到传统数组:
uint8_t _traditional[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x33 }
作为:
for (auto target : _targets)
{
if (! memcmp(target, _traditional, 6)) {
known = 1;
}
}
我收到一个数据转换错误:
error: cannot convert 'std::array<unsigned char, 6u>' to 'const void*' for argument '1' to 'int memcmp(const
void*, const void*, size_t)
我可以执行什么属性字节比较操作来完成相等性评估?
【问题讨论】:
-
为什么不将
_traditional也设为std::array并使用==? -
@Cheers 有没有办法临时施放它?它是我利用的大型第 3 方库的一部分
-
std::equal怎么样? -
小心那些领先的下划线。有时它们意味着一些特别的东西。 [在 C++ 标识符中使用下划线的规则是什么?](stackoverflow.com/questions/228783/…