Very simple string help needed
Hey guys,
I am doing an excersise from a c++ book (not for school) and am having a problem. What I am trying to do is to have the user enter a string, then enter a letter. After the letter is entered the program should tell you how many times that letter appeared in the string. Example- the user types in "hello" then the user typed in 'l' for the letter. The program should say that 'l' appears 2 times. no matter what string i type and no matter what letter i want it to find it will always print -1. WHY?
Code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string message;
int j;
cout << "Enter a String!\n";
getline(cin, message);
string SearchLetter;
cout << "Enter a letter to be searched\n ";
getline(cin, SearchLetter);
j = message.find("SearchLetter");
cout << "The number of times that letter appears in the string is " << j << endl;
system ("pause");
return 0;
}
*Edit* I got rid of the quotes in around the "SearchLetter" in the message.find() function, and now it will give me different answers but it is the wrong answer!?