469,945 Members | 1,813 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

char comparison help

HED
I am learning c++, and there is a lot that i dont know, so if this is
a stupid question, I am sorry. regardless, I am trying to get my
program to check and see if a char value is a certain value, and then
act appropriately. The compiler goes into fits when I do this, and if
I double click the error it opens ostream, and i figure that I really
have no business messing with that.

So, my code looks something like:

choice is a char and destination is a string. I think that the real
place that i have having trouble is in the comparing a char part of
the code. (basically I dont know how to do it and would like you to
tell me.) I have googled it, but I have a hard time finding code
snippets that explain how to do stuff.
if (choice = a)
destination = "someplace";
Thanks in advance for the help, if I need to post further
claification, please let me know.

--HED

Oct 11 '07 #1
4 7014
"HED" <me*************@hotmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
>I am learning c++, and there is a lot that i dont know, so if this is
a stupid question, I am sorry. regardless, I am trying to get my
program to check and see if a char value is a certain value, and then
act appropriately. The compiler goes into fits when I do this, and if
I double click the error it opens ostream, and i figure that I really
have no business messing with that.

So, my code looks something like:

choice is a char and destination is a string. I think that the real
place that i have having trouble is in the comparing a char part of
the code. (basically I dont know how to do it and would like you to
tell me.) I have googled it, but I have a hard time finding code
snippets that explain how to do stuff.
if (choice = a)
destination = "someplace";
Thanks in advance for the help, if I need to post further
claification, please let me know.

--HED
= is the assignment operator.

== is the comparison operator.

a look like a variable name. To compare choice with the char a use:
if (choice == 'a')

--
Scott McPhillips [VC++ MVP]

Oct 11 '07 #2
HED wrote:
I am learning c++ ...
Thanks in advance for the help, if I need to post further
claification, please let me know.
choice = a ?

Maybe you mean

choice == 'a'

?

Unless you define the `a` you're going to get undefined identifier
errors and if you use `=` (assignment) instead of `==` (equality
compare) you're probably not going to get behaviour you want.
Oct 11 '07 #3
HED wrote:
I am learning c++, and there is a lot that i dont know, so if this is
a stupid question, I am sorry. regardless, I am trying to get my
program to check and see if a char value is a certain value, and then
act appropriately. The compiler goes into fits when I do this, and if
I double click the error it opens ostream, and i figure that I really
have no business messing with that.

So, my code looks something like:

choice is a char and destination is a string. I think that the real
place that i have having trouble is in the comparing a char part of
the code. (basically I dont know how to do it and would like you to
tell me.) I have googled it, but I have a hard time finding code
snippets that explain how to do stuff.
if (choice = a)
Typo. Make that:

if ( choice == a )
^^
destination = "someplace";
Thanks in advance for the help, if I need to post further
claification, please let me know.
The comparison operators are

== equal
!= not equal
< less
<= less or equal (aka. not greater)
greater
= greater or equal (aka. not less)
You need to distinguish them from the assignment operators

= assignment
<<= shift in place
>>= shift in place

Best

Kai-Uwe Bux

Oct 11 '07 #4
HED
choice == 'a'
The comparison operators are

== equal
!= not equal
< less
<= less or equal (aka. not greater)
greater
= greater or equal (aka. not less)
You need to distinguish them from the assignment operators

= assignment
<<= shift in place
>>= shift in place
These are excatly (I think) what I am looking for. Thank you

Oct 11 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rob Smeets | last post: by
3 posts views Thread by Vishal Ladha | last post: by
20 posts views Thread by Jacky Cheung | last post: by
11 posts views Thread by Jason Curl | last post: by
2 posts views Thread by Henrik Goldman | last post: by
74 posts views Thread by aruna.mysore | last post: by
33 posts views Thread by Michael B Allen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.