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

Posted cthon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::sub相关的知识,希望对你有一定的参考价值。

运行时报错:

terminate called after throwing an instance of ‘std::out_of_range‘
what():  basic_string::substr
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::sub的主要内容,如果未能解决你的问题,请参考以下文章

gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex

gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex

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

学习笔记50--terminate called after throwing an instance of ‘YAML::BadFile‘ what(): bad file报错踩坑

解决程序出现“terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_a

XGB模型训练报错 terminate called after throwing an instance of ‘std::bad_alloc‘ what()