#include <iostream>
#include <string>
usingnamespace 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> ]