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