码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2018-07-22 14:05:42      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:call   core dump   char   only   str   sub   报错   解决方案   cte   

运行时报错:

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::substr

标签:call   core dump   char   only   str   sub   报错   解决方案   cte   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!