find the second aperrence of a char in string c++
#include <string>
int nthOccurrence(const std::string& str, const std::string& findMe, int nth)
{
size_t pos = 0;
int cnt = 0;
while( cnt != nth )
{
pos+=1;
pos = str.find(findMe, pos);
if ( pos == std::string::npos )
return -1;
cnt++;
}
return pos;
}