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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM