Article View: comp.std.c++
Article #2492Re: IOManipulators with two arguments?
From: Dr. Richard Botting
Date: Fri, 10 Nov 1995 01:13
Date: Fri, 10 Nov 1995 01:13
70 lines
3120 bytes
3120 bytes
Bernd Eggink (admin@rzaix13.uni-hamburg.de) wrote:
: Dr. Richard Botting (dick@silicon.csci.csusb.edu) wrote:
: > According to the 2nd addition of Horstmann's "Mastering C++",
: > cout << setiosflags(ios::fixed, ios::floatfield);
: > is OK, but I found that it would not compile because the libraries
: > on our Gnu C++ n.m.0 do not have a two argument form of the
: > iomanipulator setiosflags.
: This must be a typo. It should read
: cout.setf(ios::fixed, ios::floatfield);
It occurs several times.... suggesting that the
cout.setf
form and the iomanipulator form are equivalent.
I think this is a confusing area therefore.
: AFAIK, the library does not provide manipulators with two arguments.
: You can, of course, easily write your own.
I guess so...
[snip]
: > And if so... how does one do the euqivalent of
: > cout.setf(ios:: F, ios::G);
: > by using
: > cout<<setiosflags( X );
: You can build manipulators with 2 parameters in different ways. I
: prefer the manipulator to be a classname, so that M(x,y) is a
: temporary object.
: If you don't want to do that, you may write
: cout << resetiosflags(ios::floatfield)
: << setiosflags(ios::fixed);
This works, in this case, and lead me back to the working
papers.... and now I see what is going one here. Because the
adjustments and similar use 3 bits (8 states) to encode a choice
of three possibilities (left, right, internal for example). You
turn on one bit by
turn off all three
turn on one.
: although that is somewhat clumsy.
Bernrd said it for me.
Meanwhile, things like the following seem to work nicely:
ostream& left(ostream& out) //set left justified
{
out.setf(ios::left, ios::adjustfield);
return out;
}
Giving
cout << hex << left << 12345;
However I am suspicious of easy solutions these days, so
what have I missed?
--
dick@csci.csusb.edu=rbotting@wiley.csusb.edu.
Find out what's new at http://www.csci.csusb.edu/doc/www.sites.html
Disclaimer:`CSUSB may or may not agree with this message`.
Copyright(1995):Copy this freely but include the following link to the
<a href="http://www.csci.csusb.edu/dick/signature.html">author's signature</a>
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<47tikm$45b@news.csus.edu>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<47or96$kct@news.csus.edu> <47slkd$p5@rzsun02.rrz.uni-hamburg.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 10 Nov 95 01:13:42 GMT Approved: fjh@cs.mu.oz.au Return-Path: <daemon@migs.UCAR.EDU> From: dick@silicon.csci.csusb.edu (Dr. Richard Botting) Newsgroups: comp.std.c++ Subject: Re: IOManipulators with two arguments? X-Original-Date: 9 Nov 1995 18:52:06 GMT Organization: CS Dept., Calif. State Univ., San Bernardino Message-ID: <47tikm$45b@news.csus.edu> References: <47or96$kct@news.csus.edu> <47slkd$p5@rzsun02.rrz.uni-hamburg.de> X-Newsreader: TIN [version 1.2 PL2] X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMKKnVeEDnX0m9pzZAQFJ1AGAk5qdOu9gAx1E84Z8PbptTrRog98EVx8g WH6tVY/V6iu7ShemRbRCOHPnN3cUY4TP =k2HI