社区新版论坛已上线,点击立即前往!使用 openKylin 账户授权登录,解锁更多体验!

openKylin论坛

 找回密码

[解决] terminate called after throwing an instance of 'std::out_of_range' wha... [复制链接]

本帖最后由 bunny 于 2013-9-22 19:36 编辑

编译运行程序遇到这样的问题:
            terminate called after throwing an instance of 'std:: out_of_range'  what():  basic_string::substr   
内存读取越界。
解释1:
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.
定义的sTest只有5个字符,要去sTest的字串(0,10),显然错误。

解释2:
std::string s("foo");
s.substr(5,1); //the length of the string is 3, 5 is out of bounds
同样会报错,out_of_range


楼主
发表于 2013-9-22 19:34:42
回复

使用道具 举报

openKylin

GMT+8, 2024-6-13 16:58 , Processed in 0.016408 second(s), 17 queries , Gzip On.

Copyright ©2022 openKylin. All Rights Reserved .

ICP No. 15002470-12 Tianjin

快速回复 返回顶部 返回列表