Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string letters = "Madam I'm Adam";
size_t length = letters.length();
bool isPalindrome;
unsigned index = 0;
string testStr;
// Lowercase all the characters
// extract the letters without including punctuation and spaces
while (index < length)
{
if (isalpha(letters[index]))
testStr += tolower(letters[index]);
index++;
}
// Now check if it is a palindrome
isPalindrome = true;
for (int i = 0; i < (testStr.length() / 2); i++)
{
if (testStr[i] != testStr[testStr.length() - (i-1)])
{
isPalindrome = false;
break;
}
}
cout << "\"" << letters << "\"" << isPalindrome ? "is" : "is not"
<< " a palindrome." << endl;
return EXIT_SUCCESS;
}
I can get it to compile due to some errors which I'm unable to understand, I'm compiling it with Visual Studio 2005
The build log is
EDIT:
Got it. Was using C++/CLI so, had forgotten the parenthesis
but still there are two errors
Code:
1>------ Build started: Project: C++ConsoleTest, Configuration: Debug Win32 ------
1>Compiling...
1>test.cpp
1>c:\documents and settings\manzoor\my documents\visual studio 2005\projects\c++consoletest\c++consoletest\test.cpp(25) : warning C4018: '<' : signed/unsigned mismatch
1>c:\documents and settings\manzoor\my documents\visual studio 2005\projects\c++consoletest\c++consoletest\test.cpp(34) : error C2296: '<<' : illegal, left operand has type 'const char [7]'
1>c:\documents and settings\manzoor\my documents\visual studio 2005\projects\c++consoletest\c++consoletest\test.cpp(34) : error C2297: '<<' : illegal, right operand has type 'const char [15]'
1>Build log was saved at "file://c:\Documents and Settings\manzoor\My Documents\Visual Studio 2005\Projects\C++ConsoleTest\C++ConsoleTest\Debug\BuildLog.htm"
1>C++ConsoleTest - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Well, it would be great if told how to resolve the warning