5. Write c++ function that would intake a string and return
the number of occurrences of a given character in that sring
Ex:- if the word is “Colombo” and count the occurrences of
the letter “o” the function would return 3



5. Write c++ function that would intake a string and return the number of occurrences of a given ch..

Answer / qliubrvq

occurrences(string str, char test) {
int len = str.size();
int count = 0;
for (int i = 0; i < len; i++) {
if (str[i] == test) count++;
}
return count;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More STL Interview Questions

what is use of for loop?

9 Answers   Wipro,


i wanted to know about questions about c,c++ , which is required for placements.... im a fresher

0 Answers   NDS,


method overloading means what?

2 Answers   CTS,


what is the difference between thread and process

1 Answers   Infosys,


Name the different types of stl containers.

0 Answers  






Give the output of the following program main() {int ret; ret=fork();ret=fork();ret=fork();ret=fork(); if(!ret) printf("sun"); else printf("solaris");

8 Answers   Sun Microsystems,


What is the name of your birth place?

0 Answers  


Define the terms: field, record, table and database

5 Answers  


What are the components of stl?

0 Answers  


how to swap two numbers in a linked list without exchanging the data but only the links?

3 Answers   Wipro,


What are the symptoms of stl?

0 Answers  


Is string part of stl?

0 Answers  


Categories