600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr

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

时间:2019-08-10 00:41:08

相关推荐

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

运行时报错:

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。