#include<string>
#include<iostream>
using namespace std;
string::size_type zx(const string&s,const char& target,int&cnt)
{
auto ret = s.size();
cnt = 0;
for (decltype(ret)i = 0; i != s.size(); ++i)
{
if (s[i] == target)
{
if (ret == s.size())
ret = i;
++cnt;
}
}
return ret;
}
int main() {
string ozy = "ni shi gou ba!";
char target = 'a';
int cnt = 0;
int index = zx(ozy, target, cnt);
cout << "where:" + to_string(index) << endl;cout<< "content:"+to_string(cnt) << endl;
}
如果返回多个值, 使用引用.