| 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.
.
|
|
|
|
|

|
Related Articles |
|
|