You could do without that c_in_str function by using std::count from <algorithm>, e.g.,

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{