I have this now working program (as long as its compiled in gcc or dev-c++)
but for testing I try Vc++ V6 to make sure others can compile (im tring to create a habit)
Vc++ gives this error
error C2665: 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' : none of the 7 overloa
ds can convert parameter 1 from type 'class std::reverse_iterator<char *,char,char &,char *,int>'
Error executing cl.exe.
and this is the line it points to
Code:
if ( SetToTest == string(SetToTest.rbegin(), SetToTest.rend()) )
here is the entire program
Code:
//extra credit
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
//function prototypes
void clear_screen();
string Check (const string& );
string make_lower(const string& );
string check_Punctuation(const string& , const string& );
//main function
int main()
{
//local varables
char LineToCheck[255];
string TestInput,SetToTest;
clear_screen();
//get input and hold it in char LineToCheck, convert to string to edit and check
cout << "Enter Line that could be a palendrome:" << endl;
//get input in form required can recive up to 255 char
cin.get(LineToCheck,255);
//place input into string to process
TestInput = LineToCheck;
SetToTest = Check(TestInput);
//compair original input - punctuation and capitialization aginst
//input reverst using the inherent string class reverses
if ( SetToTest == string(SetToTest.rbegin(), SetToTest.rend()) )
cout << "your input is a palendrome" << endl;
else
cout << "your input is not a palendrome" << endl;
return 0;
}
//------Clear Screen--------------------------------------------------------
void clear_screen()
{
#if defined WIN32
system ("cls");
#elif defined UNIX
system ("clear");
#endif
}
//------Check loop----------------------------------------------------------
string Check (const string& s)
{
//create loop local strings
string punctuation(",;:.?!'\" ");
string TestString;
string LowerCheck (s);
//make all char lower case
LowerCheck = make_lower(LowerCheck);
//remove puctuation
TestString = check_Punctuation(punctuation, LowerCheck);
return TestString;
}
//------make lower case-----------------------------------------------------
string make_lower(const string& s)
{
string holder(s);
for (int i = 0; i < s.length( ); i++)
//tolower is part of the cctype lib returns lowercase version of c if there is one,
// otherwise it returns the character unchanged.
holder[i] = tolower(s[i]);
return holder;
}
//remove Punctuation funtion
string check_Punctuation(const string& punct, const string& Holder)
{
//funtion only string
string no_punctuation;
//set variables to hold length of string for loops
int holder_length = Holder.length( );
int punct_length = punct.length( );
for (int i = 0; i < holder_length; i++)
{
//create a 1 char string to hold the test canadate
string SingleChar = Holder.substr(i,1);
//Find location of successive characters that are in string punct that
int locationOfChar = punct.find(SingleChar, 0);
// SingleChar not in punct, so keep it
if (locationOfChar < 0 || locationOfChar >= punct_length)
no_punctuation = no_punctuation + SingleChar;
}
return no_punctuation;
}
if it matters VC++ in ran from xp in Vmware form my Gentoo box.. I don't believe this matters .. but I have seen stranger things.
thanks for your help