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;
10 Years
Discussion Span
Last Post by Duoas

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.