terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr
運(yùn)行時(shí)報(bào)錯:
terminate called after throwing an instance of 'std::out_of_range'
what(): ?basic_string::substr:__pos
Aborted (core dumped)
內(nèi)存讀取越界。
解釋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.
調(diào)試過,正常運(yùn)行,無報(bào)錯。
解釋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
調(diào)試過,確實(shí)會報(bào)錯,out_of_range
?
解決方案:查找substr方法前后代碼,排除可能的越界條件。
轉(zhuǎn)載于:https://www.cnblogs.com/cthon/p/9349813.html
總結(jié)
以上是生活随笔為你收集整理的terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: React开发(236):dva概念1数
- 下一篇: C编程经验总结