getLine and letter count problems

I am trying to do an assignment where my code will count a letter inputted from a sentence. The code now only examines the first word and not the entire sentence.
I also get an error, the error started when I added the getLine function.
In function 'int main()':
14:19: error: no matching function for call to 'std::basic_istream<char>::getline(char&)'
14:19: note: candidates are:
In file included from /usr/include/c++/4.9/iostream:40:0,



#include <iostream>
#include <string>
using namespace std;

int countLetters(char, char[]);
int main()
{
char let;
char text[256];
int getLine();

cout << "Enter a letter: ";
cin.getline(let);

cout << "Enter text: ";
cin.getline(text, 256);
cin.ignore();

int nCount = countLetters(let, text);
cout << "Number of '" << let << "'s: "
<< nCount << endl;
return 0;
}

int countLetters(char let, char text[])
{
int num = 0;
for(int i = 0; text[i]; i++)
{
if (text[i] == let)
num++;
}
return num;
}

int getLine()
{
char letters;

cin>> letters;
cin.ignore();

return 0;
}

Any suggestions?
Last edited on
On line 13 of your program you use cin.getline(let);

To find one character, you would want to use cin.get(let);

I also noticed that you have the "getLine" function at the end of the program that is never called upon. However, this function also returns 0 which would terminate your program if it was called upon.

Are you allowed to use strings instead of char for this assignment?
Topic archived. No new replies allowed.