网上找了半天也没找到谁写的彻底一点,还不如自己动手。
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
while(cin >> s)
{
int f = s.find("o");
cout << f << endl;
}
return 0;
}
结论:
找到就返回第一次出现的串的第一个字符位置,找不到返回-1。