basic_string.h 中的 compare(size_type pos1, size_type count1, const basic_string& other, size_type pos2, size_type count2) const 逻辑出现问题
作者: terrfg创建于 2025年3月27日更新于 2025年3月27日
// 从 pos1 下标开始的 count1 个字符与另一个 basic_string 从 pos2 下标开始的 count2 个字符进行比较 template <class CharType, class CharTraits> int basic_string<CharType, CharTraits>::compare(size_type pos1, size_type count1, const basic_string& other, size_type pos2, size_type count2) const { auto n1 = mystl::min(count1, size_ - pos1); auto n2 = mystl::min(count2, other.size_ - pos2); return compare_cstr(buffer_, n1, other.buffer_, n2); }
内容来源: Alinshans/MyTinySTL