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

匿名 (未验证) 提交于 2019-12-03 00:43:02

运行时报错:

terminate called after throwing an instance of ‘std::out_of_range‘

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方法前后代码,排除可能的越界条件。

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

原文:https://www.cnblogs.com/cthon/p/9349813.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!