Palindromes help

What is wrong with my code, i am trying to find the palindromes in a sentence. i am given this error. "error C3867: 'std::basic_string<_Elem,_Traits,_Alloc>::size': function call missing argument list; use '&std::basic_string<_Elem,_Traits,_Alloc>::size' to create a pointer to member"


#include<iostream>
#include<string>

using namespace std;

int main()
{
string sentence;
int i=0;
int size = sentence.size;

cout << "Please enter a word" << endl;
do
{
cin>>sentence;
i++;

if(sentence==string(sentence.rbegin(), sentence.rend()))
{
cout<<sentence<<" is a palindrome.\n";
}


}while(i<size);

system("pause");
return 0;
}
Last edited on
int size = sentence.size;

should be

int size = sentence.size();
also, it only goes through the first word in the input. i need all of them
1
2
string sentence;    // default constructor -> empty string ""
int size = sentence.size( );    // size == 0, since sentence is "" 


Consider changing the condition of the do-while loop. Maybe if "quit" is entered, the loop will terminate.
Topic archived. No new replies allowed.