Erro "no matching function for call to 'getline'

Hi guys,

I'm doing this program to check whether a string in a file is Palindrome or not, and everything is fine until I got these two problems
the first one is :

'no matching function for call to 'getline'

and the second one is that the file contains some whaitespaces and punctuations so even though my program doesn't compile yet, I figured that out and I have no idea how to fix this

thanks in advance


Here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <string>
#include <fstream.h>
#include <iomanip.h>
using namespace std;

int main()
{
    ifstream sentences;
    sentences.open("sentences.txt");
    ofstream palindromes;
    palindromes.open("palindromes.txt");
    if (sentences.is_open())
    {
        while ( sentences.good() )
        {
            char str[1000];
            
            getline (sentences,str);
            
            
            int len = strlen(str);
            
            int    mid = len/2, // middle of the string
            end = len-1;
            
            bool is_palindrome = true;
            
            for (int i = 0; i != mid; i++)
            {
                if (str[i] != str[end-i])
                    is_palindrome = false; // not palindrome
            }
            
            palindromes << (is_palindrome ? "It's palindrome." : "it's not palindrome.") << endl;   
        }
        sentences.close();
    }
    
    else cout << "Unable to open file"; 

    
     
        
        return 0;
    }
    
    the file sentences.txt contains:

Vanna, wanna V?
Must sell at tallest sum.
I should get an eighty. Why? Because I get an eighty in all my other classes.
Lager, Sir, is regal.
I don't need documentation. The code is obvious to me. OK, but is it to the next programmer?
Evil olive.
I never thought computer science could be such fun!
Sex at noon taxes.
You expect me to read ten chapters in two days? No, I expect you to read ten chapters over the semester.
Never odd or even.

Last edited on
I'm using Xcode on mac-book
help please guys
This variation of getline() takes a std::string not a c string. See http://www.cplusplus.com/reference/string/getline/
thanks 4 the reply mate but I tried doing like this


std::string.getline (sentences,str);

and another error emerges

"expected unqualified-id"

what's that about?

Thanks a lot
What? No!

Change line 17 to string str;
And line 22 to int len = str.size();
okay.. I did that like this

1
2
3
4
5
  string str[1000];// because I want to use array
            
            getline (sentences,str);
            
            int len = str.size();



this is what you meant?

Because I have two errors now

the no matching function for call to getline in line 19
and
"member refrence type ' string* ' (aka 'basic_string<char> is a pointer maybe you meant to use '->'?" in line 22

thanks 4 ur help, I really appreciate it
Last edited on
okay.. I did that like this
No, you don't need an array of strings. Line 31 works with my previous suggestion
that solved this problem thanks a lot, but there are still problems. actually I think the way am doing it is wrong because I think I need to reserve the whole sentence and then compare it, but I don't really know how?

also when I check the output file, it just says, " It's palindrome. " for just one time, I know that's what I wrote but I don't really know how to write it like this

1
2
3
4
5
6
7
sentences.txt                       palindromes.txt
Abba                                Abba
Tuna nut.                           Tuna nut.
Hello!                              Gnu Dung.
Gnu Dung.                           No melons, no lemon
No melons, no lemon                 Man, Oprah's sharp on A.M.!
Pali what?
Man, Oprah's sharp on A.M.!

Also, what about whitespaces, punctuations, and case sensitivity , how do I ignore them when comparing?

thanks a lot
Also, what about whitespaces, punctuations, and case sensitivity , how do I ignore them when comparing?
to do this look at this: http://www.cplusplus.com/reference/clibrary/cctype/

1
2
3
if(isalnum(str[i]))
  if (str[i] != str[end-i]) // use tolower or toupper here
    is_palindrome = false; // not palindrome 
Topic archived. No new replies allowed.