📌  相关文章
📜  字符串中子字符串的频率 c++ 代码示例

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

代码示例1
#include 
#include 
int main()
{
   int occurrences = 0;
   std::string::size_type pos = 0;
   std::string s = "FooBarFooBarFoo";
   std::string target = "Foo";
   while ((pos = s.find(target, pos )) != std::string::npos) {
          ++ occurrences;
          pos += target.length();
   }
   std::cout << occurrences << std::endl;

}