What is the most efficient way to count a number of occurrences of a substring in another string in C++? For example, I have a very huge string like
"GQWHIWQGHWGGEEEGQIHIGWHIQWGHIEEEGPHIQPIWGHQPWGPHEEEGQIHWPWGQHPQWGEEE"
and I want to count how often "EEE"
occurs.
I could go step by step in a for loop and check every letter if it's an E and if so, count them and if there are 3 e
s, increment a counter, but I guess there is a more efficient way of doing this.
Maybe a string function? I just wasn't able to find or google a suitable one.
I am searching for a clean C++11 solution.