关于std::vector使用赋值操作时程序崩溃的问题

guicaisa 2017-05-16 10:15:37
程序报错如下
#4 0x00007f7005744c03 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5 0x00007f7005744d22 in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6 0x00007f700574511d in operator new(unsigned long) () from /usr/lib64/libstdc++.so.6
#7 0x000000000043277b in __gnu_cxx::new_allocator<unsigned char>::allocate(unsigned long, void const*) ()
#8 0x000000000042e447 in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_allocate(unsigned long) ()
#9 0x000000000042afaf in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_base(unsigned long, std::allocator<unsigned char> const&) ()
#10 0x0000000000428a4b in std::vector<unsigned char, std::allocator<unsigned char> >::vector(std::vector<unsigned char, std::allocator<unsigned char> > const&) ()

想请教下各位,请问在std::vector<unsigned char>进行赋值操作的时候,什么情况下可能崩溃报错,或者请大哥分析下上述的出错原因,谢谢。
...全文
1229 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-05-17
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止
guicaisa 2017-05-17
  • 打赏
  • 举报
回复
引用 2 楼 qq_36782456 的回复:
相关代码可以展示出来嘛?
for (std::map<UInt32, std::vector<Byte> >::iterator itr = mActions.begin(); itr != mActions.end(); itr++)
	{
		std::vector<Byte> byte_v = itr->second;
		std::for_each(byte_v.begin(), byte_v.end(), byte_add);
		value["actions"][itostring(itr->first)] = std::string(byte_v.begin(), byte_v.end());
	}
	if (mCards.size())
	{
		std::vector<Byte> byte_v = mCards;
		std::for_each(byte_v.begin(), byte_v.end(), byte_add);
		value["cards"] = std::string(byte_v.begin(), byte_v.end());
	}
	if (mDiscards.size())
	{
		std::vector<Byte> byte_v = mDiscards;
		std::for_each(byte_v.begin(), byte_v.end(), byte_add);
		value["discards"] = std::string(byte_v.begin(), byte_v.end());
	}
	if (mMelds.size())
	{
		std::vector<Byte> byte_v = mMelds;
		std::for_each(byte_v.begin(), byte_v.end(), byte_add);
		value["melds"] = std::string(byte_v.begin(), byte_v.end());
	}
	if (mFlowers.size())
	{
		std::vector<Byte> byte_v = mFlowers;
		std::for_each(byte_v.begin(), byte_v.end(), byte_add);
		value["flowers"] = std::string(byte_v.begin(), byte_v.end());
	}
时光若止-Dale 2017-05-17
  • 打赏
  • 举报
回复
相关代码可以展示出来嘛?
paschen 版主 2017-05-16
  • 打赏
  • 举报
回复
先分配空间(resize),再进行赋值

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧