I have been studying online how to find the numbers of occurrence of a certain substring in a string in c++, but in my school I must not use other advance constructs and I am given the opportunity to use cstring library and loops.
Available cstring functions:
How can I accumulate the occurances AND positions of the text?
to find the numbers of occurrence of a certain substring in a string you can use your in built function of find.
For Eg. = your string is in s1;
and you want to find occurrence of certain string you can use as
it returns the first occurrence of the string to be searched(in this case its “what”) otherwise returns npos.You can use find function in many ways.
You can find more at : here. Hope it helped.