Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <lvp\String.h>
- int countOccurances(const String &word, String &key)
- /*return the number of times that key appears inside of word
- Pre: fill in
- Post: fill in*/
- {
- int count = 0;
- String myword(word);
- do
- {
- if (myword.find(key) != -1)
- {
- count ++;
- myword = myword.substr(myword.find(key)+1, myword.length());
- }
- }while(myword.find(key) != -1);
- return(count);
- }
- int main()
- {
- String a("gaben boy baby bbb");
- String b("b");
- cout<<countOccurances(a,b);
- return(0);
- }
Add Comment
Please, Sign In to add comment