Search
 
SCRIPT & CODE EXAMPLE
 

CPP

frequency of a substring in a string c++

#include <string>
#include <iostream>
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;

}
Comment

PREVIOUS NEXT
Code Example
Cpp :: pbds in c++ 
Cpp :: reverse string c++ 
Cpp :: c++ typedef 
Cpp :: change to lowercase character c++ 
Cpp :: substring to int c++ 
Cpp :: print vector of vector c++ 
Cpp :: max value of double c++ 
Cpp :: define unicode c++ 
Cpp :: how to make a loop in c++ 
Cpp :: do while loop c++ loops continuously 
Cpp :: c++ simple car game 
Cpp :: c++ if in equivalent 
Cpp :: cpp multidimensional vector 
Cpp :: c++ get environment variable 
Cpp :: cpp insert overload operator 
Cpp :: all possible permutations of characters in c++ 
Cpp :: c++ colored output 
Cpp :: c++ iterate over vector of pointers 
Cpp :: check if a string is palindrome cpp 
Cpp :: c++ vector declaration 
Cpp :: lambda c++ 
Cpp :: powershell get uptime remote computer 
Cpp :: sqrt in c++ 
Cpp :: sorting vector elements c++ 
Cpp :: iterate through map c++ 
Cpp :: function in c++ 
Cpp :: sort vector of strings 
Cpp :: c elif 
Cpp :: sort vector c++ 
Cpp :: how to download c++ portable compiler 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =