📜  如何在c ++代码示例中知道字符串中某个子字符串的数量

📅  最后修改于: 2022-03-11 14:44:45.927000             🧑  作者: Mango

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