terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr

2023-11-15

运行时报错:

terminate called after throwing an instance of 'std::out_of_range'
what():  basic_string::substr:__pos

Aborted (core dumped)

内存读取越界。

解释1:for example:
const std::string sTest( "test" );
sTest.substr( 0, 10 );
will raise the same exception, since you ask 10 characters, but only 5 ( sTest.length()) ) are available.

调试过,正常运行,无报错。

解释2:

Chances are you did something like:

std::string s("foo");

s.substr(5,1); //the length of the string is 3, 5 is out of bounds

调试过,确实会报错,out_of_range

 

解决方案:查找substr方法前后代码,排除可能的越界条件。

转载于:https://www.cnblogs.com/cthon/p/9349813.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr 的相关文章

  • 第三章-Python中的数据类型

    欢迎来到python的世界 博客主页 卿云阁 欢迎关注 点赞 收藏 留言 本文由卿云阁原创 本阶段属于练气阶段 希望各位仙友顺利完成突破 首发时间 2021年3月14日 希望可以和大家一起完成进阶之路 作者水平很有限 如果发现错误 请留言轰

随机推荐