How do I compare a charecter from a file with another character?



 DEVELOP > c-Plus-Plus > How do I compare a charecter from a file with another character?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Jonathan"
Date: 17 Jan 2005 02:40:32 PM
Object: How do I compare a charecter from a file with another character?
I've tried:
char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();
but get the error
ISO C++ forbids comparison between pointer and integer
How do I work around this issue?
Thanks,
Jonathan
.

User: "Mike Wahler"

Title: Re: How do I compare a charecter from a file with another character? 17 Jan 2005 02:57:00 PM
"Jonathan" <turn@alltel.net> wrote in message
news:BpVGd.12$811.1@fe61.usenetserver.com...

I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?

Compare with a character.
if(ch == 'z')
-Mike
.

User: "Victor Bazarov"

Title: Re: How do I compare a charecter from a file with another character? 17 Jan 2005 02:46:07 PM
Jonathan wrote:

I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")

If you want to compare a character with a character, you need to
use
if (ch == 'z')
"z" is a _string_literal_ and not a _character_.

cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?

By reading the right books. What book are you reading that doesn't
explain the difference between 'z' and "z"?
V
.

User: "puzzlecracker"

Title: Re: How do I compare a charecter from a file with another character? 17 Jan 2005 02:45:45 PM
watch out for 'z' in if (ch == 'z')
Jonathan wrote:

I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?

Thanks,
Jonathan

.
User: "Jonathan"

Title: Re: How do I compare a charecter from a file with another character? 17 Jan 2005 04:01:29 PM
"puzzlecracker" <ironsel2000@gmail.com> wrote in message
news:1105994745.381302.173110@z14g2000cwz.googlegroups.com...

watch out for 'z' in if (ch == 'z')
Jonathan wrote:

I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?

Thanks,
Jonathan


Thank you very much. That took care of the problem.
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER