bitset崩溃

combobox2013 combobox2013 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
byte testBytes[5]={0x1,0x2,0x3,0x4,0x0}; //vc环境下

std::string strHelp((char*)testBytes);
#if 1
int nTemp=strHelp.length(); //nTemp==4 ?
#endif
std::bitset<40> temp2(strHelp); //崩溃



template<class _Elem,
class _Tr,
class _Alloc>
explicit bitset(const basic_string<_Elem, _Tr, _Alloc>& _Str,
_BITSET_SIZE_TYPE _Pos = 0)
{ // construct from [_Pos, ...) elements in string
_Construct(_Str, _Pos,
basic_string<_Elem, _Tr, _Alloc>::npos, (_Elem)'0');
}

最终导致

void _Xinv() const
{ // report invalid string element in bitset conversion
_THROW(invalid_argument, "invalid bitset<N> char");
}
抛出异常



需求: 用bitset模版类去操作字节数组testBytes!


...全文
评论 10
收藏 已收藏
分享
返回顶部
combobox2013
C++ 语言 65,212 成员 250,513 内容