【发布时间】:2021-01-06 03:08:13
【问题描述】:
我从这个函数中得到警告:
std::pair<size_t, size_t> GetSection(const string& s1, const string& s2) {
size_t top_section = s1.find(s2 + ":");
size_t bottom_section = s1.find(s1.length() - top_section);
return std::make_pair(top_section, bottom_section);
}
我不明白是什么转换导致了问题。 我也明白这个函数可以这样写:
std::pair<size_t, size_t> GetSection(const string& s1, const string& s2) {
size_t top_section = s1.find(s2 + ":");
size_t bottom_section = top_section + s2.length() + 1;
return std::make_pair(top_section, bottom_section);
}
我只是想知道为什么会收到此警告。
【问题讨论】:
-
s1.find(s1.length() - top_section);find应该是什么?
标签: c++