JOURNAL ENTRY

【自用】an instance of 'std::out_of_range 错误记录

今天在写代码的时候,发现程序虽然过编译了,但是运行的时候会显示:

terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 18446744073709551613) > this->size() (which is 11)

百度后发现是因为内存问题,一般出现在 std::string.substr() 中。

经过检查,我发现是 substr 的初始位置有可能变为负数,加了一个特判就好了。

END OF ARTICLE

继续阅读

评论 (0)

取消