s.find(c)如果char c不在字符串中,应该返回什么.我的意思是它在任何地方描述,因为c ++文档通常不会说最重要的事情.
编辑:更清楚:find返回我们正在寻找的字符索引,如果它(字符)不存在怎么办?
当字符不在字符串中时,将std::string::npos返回特殊索引值.
size_t index = s.find(c);
if (index == string::npos)
cout << "not found" << endl;
else
cout << "found at " << index << endl;
Run Code Online (Sandbox Code Playgroud)
更多细节和示例可以在这里找到: