+ 5
You can use find(), find_first_of() methods of string class, with a loop simply to find frequency..
https://www.geeksforgeeks.org/string-find-in-cpp/amp/
+ 3
Manav Roy,
It's not about efficiency, it's about comparison. .find() returns an unsigned integer type, on the other hand `int` is a signed integer type.
Due to the difference in signedness (https://en.m.wikipedia.org/wiki/Signedness) of those types, we may get warnings when we try to compare two integers having different signedness nature. Mainly because unsigned integer types does not accept negative values.
When a negative value is assigned to a variable of unsigned integer type, the value will be calculated as max-positive-value-of-the-type, subtracted by the negative value itself (cmiiw).
Considering the possibility of such cases, comparison of integers from different signedness nature is not encouraged, and good compilers usually warns about it.
+ 3
Yes. As ipang told.
If you use int then compare with condition
( found != -1 )
If use size_t then use
( found != string::npos)
+ 2
Manav Roy,
The .rfind() method is probably the one you seek for
https://m.cplusplus.com/reference/string/string/rfind/
+ 1
I don't know of any Methode but I would most likely try looking for the same chars and if multiply cases are there make a string out of them until a Change happen in the word.
But I also don't know how to program that yet.
edit: Maybe making the looking for Methode def = 0, but when we found other beginning letters giving the int value of that Position and start another Look tho.
+ 1
If it not returned -1 then add "Bro".length()-1 to result
if you are trying for next index then just add 1, it works.