【发布时间】:2018-11-12 13:59:49
【问题描述】:
我想完成以下操作(代码不会像编写的那样编译,因为>> 没有为std::array 重载):
constexpr array<char, 2> MAGIC_BYTES { 40, 23 };
void VerifyMagicHeader(istream& stream)
{
//Read in the bytes that should be the magic bytes
array<char, 2> buffer;
stream >> buffer //This is the line that won't compile;
if (buffer != MAGIC_BYTES)
{/*throw exception here...*/}
}
我知道我可以阅读 char[2] 而不是 std::array<char, 2> 并让它工作,但它不会那么优雅。这似乎是一个对std::array 非常有帮助的运算符,所以我想知道是否有它没有实现的原因,或者我是否需要自己实现它。
【问题讨论】: