Find the Palindrome

Hey guys, can you look at my program and help me figure out how to get this program to find the palindrome? Here is my program:

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <string>

using namespace std;
using std::string;

int main()
{
	while (true)
	{

	system ("Color 0C");

	string s;
	string sentence = s;
	int x = 0;
	int start = 0;
	string palindrome;
	string P;

	int srt_pos=0;
	int end_pos=0;
 
	cout<< "Please enter a sentence to see if it is a palindrome. \n" <<endl;
	getline(cin,s);

	while(end_pos!=-1)
	{
		srt_pos = end_pos;
		end_pos=s.find(" ",end_pos+1);


		int get_word=end_pos - srt_pos;


		if(srt_pos==0)srt_pos = -1;


		cout<<s.substr(srt_pos+1,get_word)<<'\n';		//puts words in a vertical collumn
	}


	if (sentence = string(sentence.rbegin(), sentence.rend()))	//the process to see if the user's string is a palindrome
											//s.rbegin() reverses the line inputted - its reverse beginning
											//s.rend() reverses the reverse beginning - makes sure that the input is exact frontwards and backwards
	{
		palindrome = sentence;

		while (x != -1)
		{
			cout<<"\n";
			x = s.find(palindrome, start+1);				//looks for spaces start+1 has it go to the next position after it finds the first space
			start=start+x;			
			
			if(x != -1) 
			cout<< x << endl;						//outputs how many there are
		}
		
		cout<< '\n' << palindrome << " is a Palindrome! \n" <<endl;
	}

	int repeat = 0;	//repeats program
	while(repeat == 0){

	char YesNo;

	cout<< "Would you like to run the program again? (y/n): ";
	cin>>YesNo;
	switch (YesNo)
	{
		case 'Y': case 'y':

		repeat = 1;
		system ("cls");
		break;

		case 'N': case 'n':
		return 0;

		default:
		cout<< "Invalid answer." <<endl;
		system ("pause");
		break;
	}
	}
	}
}


the error I get is on line 43:

c:\documents and settings\karbowiakm14\desktop\c++\find the palindrome\find the palindrome\find the palindrome.cpp(44): error C2451: conditional expression of type 'std::basic_string<_Elem,_Traits,_Ax>' is illegal
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]

Help ASAP, thanks.
if (sentence == string(sentence.rbegin(), sentence.rend()))//<<<< ==
OMFG -.- I can't believe I overlooked that. Thanks. I just need to correctly output everything. Any tips?

EDIT I'm heading out of the class so I will check for updates later
Last edited on
Topic archived. No new replies allowed.