* Proper and portable ways using manipulator
@ 2003-08-07 22:21 Wei Qin
2003-08-08 4:46 ` LLeweLLyn Reese
0 siblings, 1 reply; 4+ messages in thread
From: Wei Qin @ 2003-08-07 22:21 UTC (permalink / raw)
To: gcc-help
Hi,
I used some manipulators in the form of
#include <iostream>
#include <ios>
int main () {
std::cout << std::showbase << std::hex << 100 << std::endl;
}
This compiles fine with g++ 3.x. However, it fails on g++ 2.96
since it cannot find ios. When I remove ios, it cannot find showbase. Then
I change std::showbase to std::ios::showbase, but this showbase is not a
manipulator any more. As a result the program outputs 8064 instead of
0x64.
So my question is: Is there any good coding practice to make sure
that the same code compiles for both and works as intended? Thanks.
Wei
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Proper and portable ways using manipulator
2003-08-07 22:21 Proper and portable ways using manipulator Wei Qin
@ 2003-08-08 4:46 ` LLeweLLyn Reese
2003-08-08 5:05 ` Wei Qin
0 siblings, 1 reply; 4+ messages in thread
From: LLeweLLyn Reese @ 2003-08-08 4:46 UTC (permalink / raw)
To: Wei Qin; +Cc: gcc-help
Wei Qin <wqin@EE.Princeton.EDU> writes:
> Hi,
> I used some manipulators in the form of
>
> #include <iostream>
> #include <ios>
Try:
#include <iomanip>
instead. (Note: I don't have 2.96 availible to test.)
>
> int main () {
>
> std::cout << std::showbase << std::hex << 100 << std::endl;
> }
>
> This compiles fine with g++ 3.x. However, it fails on g++ 2.96
> since it cannot find ios. When I remove ios, it cannot find showbase. Then
> I change std::showbase to std::ios::showbase, but this showbase is not a
> manipulator any more. As a result the program outputs 8064 instead of
> 0x64.
> So my question is: Is there any good coding practice to make sure
> that the same code compiles for both and works as intended? Thanks.
Compile every change with both compilers.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Proper and portable ways using manipulator
2003-08-08 4:46 ` LLeweLLyn Reese
@ 2003-08-08 5:05 ` Wei Qin
2003-08-08 5:44 ` LLeweLLyn Reese
0 siblings, 1 reply; 4+ messages in thread
From: Wei Qin @ 2003-08-08 5:05 UTC (permalink / raw)
To: LLeweLLyn Reese; +Cc: gcc-help
Hi, LLeweLLyn,
Thanks for the reply.
I tried <iomanip>, it works for g++3, but again not for g++2.
I grepped its g++-2 directory and the only showbase that I found is an enum.
So I now assume that there is no showbase manipulator in that library.
Is there any similar backward compatible way to use manipulators as
the hash_map one given at
http://gcc.gnu.org/onlinedocs/libstdc++/faq/#5_4
?
Wei
On 7 Aug 2003, LLeweLLyn Reese wrote:
> Wei Qin <wqin@EE.Princeton.EDU> writes:
>
> > Hi,
> > I used some manipulators in the form of
> >
> > #include <iostream>
> > #include <ios>
>
> Try:
> #include <iomanip>
>
> instead. (Note: I don't have 2.96 availible to test.)
>
> >
> > int main () {
> >
> > std::cout << std::showbase << std::hex << 100 << std::endl;
> > }
> >
> > This compiles fine with g++ 3.x. However, it fails on g++ 2.96
> > since it cannot find ios. When I remove ios, it cannot find showbase. Then
> > I change std::showbase to std::ios::showbase, but this showbase is not a
> > manipulator any more. As a result the program outputs 8064 instead of
> > 0x64.
> > So my question is: Is there any good coding practice to make sure
> > that the same code compiles for both and works as intended? Thanks.
>
> Compile every change with both compilers.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Proper and portable ways using manipulator
2003-08-08 5:05 ` Wei Qin
@ 2003-08-08 5:44 ` LLeweLLyn Reese
0 siblings, 0 replies; 4+ messages in thread
From: LLeweLLyn Reese @ 2003-08-08 5:44 UTC (permalink / raw)
To: Wei Qin; +Cc: gcc-help
Wei Qin <wqin@EE.Princeton.EDU> writes:
> Hi, LLeweLLyn,
>
> Thanks for the reply.
> I tried <iomanip>, it works for g++3, but again not for g++2.
> I grepped its g++-2 directory and the only showbase that I found is an enum.
> So I now assume that there is no showbase manipulator in that
> library.
Probably correct.
>
> Is there any similar backward compatible way to use manipulators as
> the hash_map one given at
> http://gcc.gnu.org/onlinedocs/libstdc++/faq/#5_4
> ?
[snip]
I don't know. I doubt it; there's backward/iostream.h , but it just
#includes <iostream> and adds using declarations to bring
appropriate things into the global namespaces. Same for the other
iostream headers in backward/.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-08-08 5:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-07 22:21 Proper and portable ways using manipulator Wei Qin
2003-08-08 4:46 ` LLeweLLyn Reese
2003-08-08 5:05 ` Wei Qin
2003-08-08 5:44 ` LLeweLLyn Reese
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).