1、map.find与std::find的返回值:
unordered_map<int, int> mymap;
mymap.insert({1,2});
auto it = mymap.find(1); // 返回值为迭代器
if (it != mymap.end()) { // 不存在返回尾迭代器mymap.end()
cout << it->first << it->second << endl;
}
返回值为迭代器,找不到返回***.end()。
2、string.find的返回值:
string s("abcd");
std::size_t pos = s.find("ab"); // 返回值为下标位置(uint型)
if (pos != std::string::npos) { // 不存在返回string::npos
cout << "find it at pos: " << pos << endl;
}
返回值为在string中的下标位置,找不到返回std::string::npos。