I am trying to understand how [bool hasaletter(string, char(c))] works. after boolhasaletter appears, if it is true, i want to add to total_num.
I have tried if(true) {
and it did not work.
so basically, im trying to see if a string has a character user inputted.

int main()
{
int total_num
char c;
ifstream infile("data.txt");
string a_word[2];
cout << "enter a letter";
cin >> c;
while(infile >> a_word)
{
bool hasaletter(string, char (c));
  // what needs to be in this line????
++total_num;      //if the above statement is true i want to add 1 to total_num


return 0;
}
Member Avatar for iamthwee

You could use the string find method, or seeing as it is just single characters, you could loop through each character in the string to see it if matches.

You need to read up on how to declare a function and how to call a function.

The function you are trying to use is declared as: bool hasaletter( string, char ); To use it: if (hasaletter( "1024x768", 'x' )) cout << "It sure does...\n"; Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.