int nPos = str_to_search.find(str, 0); while (nPos != string::npos) { count++; nPos = str_to_search.find(str, nPos + str.size()); }