Anyone here proficient with c++?

GQ NSX

Registered Member
Joined
27 April 2003
Messages
614
Location
So Cal
Hi there guys. I'm having trouble with my c++ program, just wondering if anyone here can give me a little help? It's a program for testing for palindromes. I keep on getting the error: C:\adkfj\asdfa.cpp(30) : error C2676: binary '&&' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
where it is bolded in the program:


thanks for any help guys.


#include < iostream >
#include < string >
#include < stdio.h >

using namespace std;

char uppercase(char c);
bool character(char c);

void main()

{



string palindrome;
string s;
int left = 0;
int right = s.size() - 1;


cout << " Input your work or phrase or 'stop' "<< endl;

cin >> palindrome;


palindrome = true;
while (palindrome && left<= right)
{
if (upperase (s[left++])!=uppercase(s[right--])
palindrome=false;
else
palindrome= true;
}





void getLine(string& s)
{
char c;
s = "";
c = getchar();
while ( c >= '')
{
s += c;
c = getchar();
}
char uppercase(char c);
{
if (c >='a' && c <='z')
return (c -32);
else
return c;
}

bool character(char c)
{
if ((c >= 'a' && c <= 'z')
||
(c >= 'A' && c <= 'Z')
||
( c >='0' && c < = '9' ))
return true;
else
return false;
}
}

cout << endl << " Input your work or pharse or 'stop' " << endl;
cin >> palindrome;

}

}
 
The compiler is complaining because the string class does not define a && operator.

Palindrome is defined as a string.

You need to supply a type which has defines the && operator, like a boolean.

Hope that helps.

NSX-Stalker
 
Last edited:
Hello NSX stalker:

Thank you for your prompt response. I just started workign with c, and am having basic errors. I really appreciate your help. I edited the program some more, yet got two more errors--if you have a few minutes free could you possibly point me in the right direction? The following is the program, with two errors.


error C2143: syntax error : missing ';' before 'constant' <---this points to where it is bold, when i debug


fatal error C1004: unexpected end of file found
Error executing cl.exe. <---i assume this is a missing }, however there are an even number here? thanks again.




#include < iostream>
#include < string>
#include < stdio.h>

using namespace std;

char uppercase(char c);
bool character(char c);

void main()

{

cout << " COMP51-1, Spring 2004 " << endl; //output class and year
cout << " Assignment #6 " << endl; // output assignment number
cout << " Ravi Mohan " << endl << endl; //output programmer name

string palindrome;
string s;
int left = 0;
int right = s.size() - 1;


cout << " Input your work or phrase or 'stop' "<< endl;

cin >> palindrome;

palindrome = true;

while (palindrome.length() > 0)
{
while (! character (uppercase(s
)))
left ++;
while (! character (uppercase(s
)))
right --;

}

cout << endl << " Input your work or pharse or 'stop' " << endl;
cin >> palindrome;

}

char uppercase (char c)false;
{
if (c >='a' && c <='z')
return (c -32);
else
return c;
}

bool character(char c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || ( c >='0' && c < = '9' ))
return true;
else
return false;
}

void getLine(string& s)
{
char c;
s = "";
c = getchar();
while ( c >= '')
{
s += c;
c = getchar();
}
}​
 
You're welcome.

I would not worry about the second error until you fix the first. Your function definition should be

char uppercase (char c)

drop the false and the semicolon and that should fix the first and may fix the second. You're right in assuming that you're missing a paren but the compiler is most likely confused at that point due to the previous error.

If you'd like I can recommend a few C++ books to help you get started. C++ can be a beast to work with and it's best to have a good set of reference material to use.

NSX-Stalker
 
STOCKTONSX said:
palindrome = true;
while (palindrome && left<= right)
{
if (upperase (s[left++])!=uppercase(s[right--])
palindrome=false;
else
palindrome= true;
}

You have also spelled uppercase incorrectly...
And I also agree with the boolean/ string problem discussed before.
 
Back
Top