Re: beginner string question
From: Catalin Pitis (catalin.pitis.removeme_at_iquestint.com)
Date: 11/12/03
- Next message: moi: "lottery number thing problem"
- Previous message: Frank Schmitt: "Re: Help Needed!! Marshalling Message"
- In reply to: Sonoman: "beginner string question"
- Next in thread: Sonoman: "Re: beginner string question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 Nov 2003 10:30:02 +0200
Hi,
see below
"Sonoman" <fcarpio@cse.fau.edu> wrote in message
news:Skksb.11179$jA6.6383@bignews6.bellsouth.net...
> I am trying to do this:
>
> cin >> temp;
> if (temp == "n"){
> Then do something...
> }
>
> temp was declared as a string and the input I give at the prompt is n, but
> it skips the condition for the if statement when I think it should go into
> the if statement. I tried swithching to 'n' for the condition but it gave
me
> a compile error. The complete code is here:
>
> http://www.cse.fau.edu/~fcarpio/
>
Couldn't find the code you mentioned.
> and the offending lines are in the person.cpp file line 66. I know it must
> be something simple, but I am failing to see it. There is no compiler
error.
>
Use std::string instead of plain C-style strings. If you declared temp
something as:
char temp[ SOME_LEN];
then temp == "n" will compare two pointers instead of two strings. The
result of comparing will be always false.
If you use std::string like:
std::string temp;
then the operator== is overloaded and it will compare the two strings.
Catalin
- Next message: moi: "lottery number thing problem"
- Previous message: Frank Schmitt: "Re: Help Needed!! Marshalling Message"
- In reply to: Sonoman: "beginner string question"
- Next in thread: Sonoman: "Re: beginner string question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|