关于C++的string报错处理

错误:terminate called after throwing an instance of 'std::logic_error'
 what():  basic_string::_S_construct NULL not valid

<mark>解决方式:c++和java不一样,string不允许接收NULL,注意看有没有这种操作,如果有要换成""</mark>

错误:terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at

<mark>解决方式:c++string种的at方法是会抛异常的,比如不能够干这样的事:str.at(i) == 0,就是试图用at方法判断是不是末尾0,可以改成操作符[]访问,或者用迭代器。同时这种错误还有另外一种可能就是将空的字符串""压入向量vector时也会有这个错误</mark>

全部评论

相关推荐

白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务