C++ string.at() 函数越界异常示例
给定的程序会输出以下结果:
'basic_string::at: __n (which is 5) >= this->size() (which is 5)'
该程序使用 string.at() 函数访问字符串中索引为 5 的字符,但字符串的长度只有 5,因此发生了越界访问。程序使用 try-catch 块捕获了 out_of_range 异常,并输出异常信息。
原文地址: https://www.cveoy.top/t/topic/ldq 著作权归作者所有。请勿转载和采集!