Discussion:
How do I compare a charecter from a file with another character?
(too old to reply)
Jonathan
2005-01-17 20:40:32 UTC
Permalink
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
puzzlecracker
2005-01-17 20:45:45 UTC
Permalink
watch out for 'z' in if (ch == 'z')
Post by Jonathan
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
Jonathan
2005-01-17 22:01:29 UTC
Permalink
Post by puzzlecracker
watch out for 'z' in if (ch == 'z')
Post by Jonathan
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.

Victor Bazarov
2005-01-17 20:46:07 UTC
Permalink
Post by Jonathan
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_.
Post by Jonathan
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
Mike Wahler
2005-01-17 20:57:00 UTC
Permalink
Post by Jonathan
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
Loading...