Topic: IOManipulators with two arguments?


Author: dick@silicon.csci.csusb.edu (Dr. Richard Botting)
Date: 1995/11/10
Raw View
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. ]





Author: admin@rzaix13.uni-hamburg.de (Bernd Eggink)
Date: 1995/11/13
Raw View
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. ]