Thread View: comp.std.c++
4 messages
4 total messages
Started by Dr. Richard Botting
Wed, 08 Nov 1995 10:07
IOManipulators with two arguments?
Author: Dr. Richard Botting
Date: Wed, 08 Nov 1995 10:07
Date: Wed, 08 Nov 1995 10:07
38 lines
1776 bytes
1776 bytes
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.
In the draft standard/working papers (HTML version) I searched
for all occurences of setisoflags and failed to
find anything but a one argument form:
smanip setiosflags (ios_base::fmtflags mask);
Similarly for resetiosflags.
I presume that this is deliberate and that there is a
way of expressing the older pair of arguments in terms
of a single argument.
Am I right?
And if so... how does one do the euqivalent of
cout.setf(ios:: F, ios::G);
by using
cout<<setiosflags( X );
--
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. ]
Re: IOManipulators with two arguments?
Author: Bernd Eggink
Date: Thu, 09 Nov 1995 11:10
Date: Thu, 09 Nov 1995 11:10
55 lines
2456 bytes
2456 bytes
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); AFAIK, the library does not provide manipulators with two arguments. You can, of course, easily write your own. > In the draft standard/working papers (HTML version) I searched > for all occurences of setisoflags and failed to > find anything but a one argument form: > smanip setiosflags (ios_base::fmtflags mask); > Similarly for resetiosflags. > I presume that this is deliberate and that there is a > way of expressing the older pair of arguments in terms > of a single argument. > Am I right? > 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); although that is somewhat clumsy. Bernd -- +----------------------------------+ | Bernd Eggink | | Rechenzentrum Uni Hamburg | | admin@rzaix13.rrz.uni-hamburg.de | +----------------------------------+ --- [ 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. ]
Re: IOManipulators with two arguments?
Author: 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. ]
Re: IOManipulators with two arguments?
Author: Bernd Eggink
Date: Mon, 13 Nov 1995 17:22
Date: Mon, 13 Nov 1995 17:22
34 lines
1511 bytes
1511 bytes
Dr. Richard Botting (dick@silicon.csci.csusb.edu) wrote:
[ ... ]
> 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?
It's OK (even in C++ there are some cases which look simple _and_
work). In fact, the forthcoming standard library will contain a
manipulator for each flag bit - left, right, fixed and so on.
Bernd
--
+----------------------------------+
| Bernd Eggink |
| Rechenzentrum Uni Hamburg |
| admin@rzaix13.rrz.uni-hamburg.de |
+----------------------------------+
---
[ 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads