1 代码示例

#include <iostream>

using namespace std;

int GetRepeatCountInStr(const std::string & strStream, const std::string& str)
{
    int count = 0;
    int begin = -1;
    while ((begin = strStream.find(str, begin + 1)) != std::string::npos)
    {
        count++;
        begin = begin + str.length() - 1;
    }
    return count;
}

int main()
{

    std::string str1 = "你个扑街啊啊啊啊你个扑街你个扑街";
    std::string tempStr = "你个扑街";

    int count = GetRepeatCountInStr(str1, tempStr);

    return 0;
}