| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"JustSomeGuy" |
| Date: |
05 Dec 2004 01:21:13 PM |
| Object: |
> is printing as 62 and < is printing as 60 |
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
.
|
|
| User: "Jeremy A. Smith" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
05 Dec 2004 02:18:49 PM |
|
|
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
I"m new here and this may be an obvious statement, but what it looks like
it's priniting is the ascii values for "<" and ">"
.
|
|
|
| User: "JustSomeGuy" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
05 Dec 2004 02:46:36 PM |
|
|
"Jeremy A. Smith" <jeremys73@comcast.net> wrote in message
news:luGdnXGXxOCo8C7cRVn-iw@comcast.com...
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
I"m new here and this may be an obvious statement, but what it looks like
it's priniting is the ascii values for "<" and ">"
Yes exactly.. it is treating all 'x' or '<' or what ever is single quoated
as a
integer rather than a character... it is therefor printing the ascii code
for the character.
.
|
|
|
|
|
| User: "adbarnet" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
05 Dec 2004 01:33:21 PM |
|
|
'<' is character code 62, and '>' is character code 60 - the stream operator
just sees them as ints - cout << "<" would work.
ad
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
.
|
|
|
| User: "JustSomeGuy" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
05 Dec 2004 02:01:17 PM |
|
|
"adbarnet" <adbarnet@barnet.com> wrote in message
news:41b362e7_1@127.0.0.1...
'<' is character code 62, and '>' is character code 60 - the stream
operator
just sees them as ints - cout << "<" would work.
ad
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
Sorry I obviously haven't posted all the code here..
but when I try
cout << "<"
it prints out the address of the "<" string.
.
|
|
|
| User: "Rob Williscroft" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
05 Dec 2004 02:14:13 PM |
|
|
JustSomeGuy wrote in news:hOJsd.434542$nl.182628@pd7tw3no in
comp.lang.c++:
"adbarnet" <adbarnet@barnet.com> wrote in message
news:41b362e7_1@127.0.0.1...
'<' is character code 62, and '>' is character code 60 - the stream
operator
just sees them as ints - cout << "<" would work.
ad
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
Sorry I obviously haven't posted all the code here..
but when I try
cout << "<"
it prints out the address of the "<" string.
Are you including <ostream> ?
#include <iostream> /* for std::cout */
#include <ostream> /* for the << operators & std::endl */
int main()
{
std::cout << '<' << "<" << std::endl;
}
Rob.
--
http://www.victim-prime.dsl.pipex.com/
.
|
|
|
| User: "Arijit" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
08 Dec 2004 02:26:00 PM |
|
|
Rob Williscroft wrote:
Are you including <ostream> ?
#include <iostream> /* for std::cout */
#include <ostream> /* for the << operators & std::endl */
You have to include ostream separately ?! I didn't know that. I have
never had to do it even once. And I have used quite a few compilers.
Plain lucky ?
-Arijit
.
|
|
|
| User: "Jonathan Mcdougall" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
08 Dec 2004 09:16:55 PM |
|
|
Arijit wrote:
Rob Williscroft wrote:
Are you including <ostream> ?
#include <iostream> /* for std::cout */
#include <ostream> /* for the << operators & std::endl */
You have to include ostream separately ?! I didn't know that. I have
never had to do it even once. And I have used quite a few compilers.
Plain lucky ?
Yes.
Jonathan
.
|
|
|
|
|
|
| User: "msalters" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
07 Dec 2004 08:04:54 AM |
|
|
JustSomeGuy wrote:
"adbarnet" <adbarnet@barnet.com> wrote in message
news:41b362e7_1@127.0.0.1...
'<' is character code 62, and '>' is character code 60 - the stream
operator
just sees them as ints - cout << "<" would work.
ad
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
Sorry I obviously haven't posted all the code here..
but when I try
cout << "<"
it prints out the address of the "<" string.
That's the obvious giveaway. You're getting the member
operator<<(void*) not the non-member operator(char*) because
your <iostream> does not include <ostream> (that's legal, but
uncommon - hence many people forget <ostream> )
Regards,
Michiel Salters
.
|
|
|
|
| User: "msalters" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
07 Dec 2004 08:05:11 AM |
|
|
JustSomeGuy wrote:
"adbarnet" <adbarnet@barnet.com> wrote in message
news:41b362e7_1@127.0.0.1...
'<' is character code 62, and '>' is character code 60 - the stream
operator
just sees them as ints - cout << "<" would work.
ad
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
Sorry I obviously haven't posted all the code here..
but when I try
cout << "<"
it prints out the address of the "<" string.
That's the obvious giveaway. You're getting the member
operator<<(void*) not the non-member operator(char*) because
your <iostream> does not include <ostream> (that's legal, but
uncommon - hence many people forget <ostream> )
Regards,
Michiel Salters
.
|
|
|
| User: "JustSomeGuy" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
07 Dec 2004 10:24:27 PM |
|
|
"msalters" <Michiel.Salters@logicacmg.com> wrote in message
news:1102428311.147233.56000@z14g2000cwz.googlegroups.com...
JustSomeGuy wrote:
"adbarnet" <adbarnet@barnet.com> wrote in message
news:41b362e7_1@127.0.0.1...
'<' is character code 62, and '>' is character code 60 - the stream
operator
just sees them as ints - cout << "<" would work.
ad
"JustSomeGuy" <nope@nottelling.com> wrote in message
news:JcJsd.415656$Pl.248656@pd7tw1no...
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
Sorry I obviously haven't posted all the code here..
but when I try
cout << "<"
it prints out the address of the "<" string.
That's the obvious giveaway. You're getting the member
operator<<(void*) not the non-member operator(char*) because
your <iostream> does not include <ostream> (that's legal, but
uncommon - hence many people forget <ostream> )
Regards,
Michiel Salters
Ok I tried including <ostream> that didn't help...
however delving deeper into this class I found that it is inheriting from
std::streambuf and has a overflow method... and I'm thinking that somehow
to_char_type is not being called somehow.
int_type overflow(int_type ch)
{
if (traits_type::not_eof(ch))
{
if (at_start)
{
for (int i = 0; i < level; ++i)
{
if (log_on)
{
buffer->sputc(traits_type::to_char_type('\t'));
}
}
}
if (log_on)
buffer->sputc(traits_type::to_char_type(ch));
if (traits_type::eq_int_type(ch, traits_type::to_int_type('\n')))
{
at_start = true;
}
else
{
at_start = false;
}
}
return ch;
}
.
|
|
|
| User: "msalters" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
09 Dec 2004 05:39:39 AM |
|
|
JustSomeGuy wrote:
Ok I tried including <ostream> that didn't help...
however delving deeper into this class I found that it is inheriting
from
std::streambuf and has a overflow method... and I'm thinking that
somehow
to_char_type is not being called somehow.
The hard part of bugfixing is when you have more than one bug.
Anyway, you must have mistracked somewhere. ostream doesn't have
an IS-A relation with streambut, but a HAS-A. This is important,
because you can replace that streambuf at runtime. std::cout
will have a special one that streams to the screen.
Anyway, the tricky part with the int_type is to deal with the number
of possible results when trying to get a character. There are
typically 257 results: either one of 256 characters, or EOF (-1).
That won't fit in an char, so an int is used. Streams are templatized
(work on wchar as well) and that's why you can't use int directly.
Anyway, the mapping from int to char (and to wchar_t from whatever
it maps from) is done by to_char_type. That is pretty much a no-op,
and I can't imagine that failing.
Regards,
Michiel Salters
.
|
|
|
|
|
|
|
|
| User: "Rob Williscroft" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
05 Dec 2004 01:48:10 PM |
|
|
JustSomeGuy wrote in news:JcJsd.415656$Pl.248656@pd7tw1no in comp.lang.c++:
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
It maybe that you are runing your compiler in some non-standard
mode and the type of '<' is not char. There isn't AFAICT any
flag you can set for std::ostream's that causes this to happen.
#include <iostream>
int main()
{
std::cout << '<' << (int)'<' << '\n';
}
The above outputs "<60\n" for me.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
.
|
|
|
|
| User: "Sumit Rajan" |
|
| Title: Re: > is printing as 62 and < is printing as 60 |
05 Dec 2004 01:32:31 PM |
|
|
JustSomeGuy wrote:
why would cout << '<' print 62
and cout << '>' print 60
Is there some flag that I have clobbered?
Something like the following code gives you that output?
#include <iostream>
int main()
{
std::cout << '<';
}
--
Sumit Rajan <sumit.rajan@gmail.com>
.
|
|
|
|

|
Related Articles |
|
|