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
#include <iostream>
#include <string>
#include <fstream.h>
#include <iomanip.h>
usingnamespace 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.
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
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?