I am trying to code the number of occurences of 'e' in a particular string but it is giving me error while defining the function as it says string is not defined in this scope and occurence_e(which is my user-def function) to be not declared in this scope as well. Following is the code:
#include<iostream>
#include<string.h>
void occurence_e(string);
using namespace std;
int main(){
string input;
cout<<"Enter any name"<<endl;
cin>>input;
occurence_e(input);
return 0;
}
void occurence_e(string input){
int count=0;
for (int i = 0; i < input.length(); i++)
{
if(input.at(i)=='e'){
count++;
}
}
cout<<"No. of times e comes in this name is "<<count;
}
The forward reference uses string
, so move using namespace std;
above it.
using namespace std;
void occurence_e(string);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments