ostream mainpulators

M

Marc Schellens

do I have to specify the field width, precisison etc.
for every object output new?
Isn't there a way to set those constantly on a stream?
thanks,
marc
 
A

Attila Feher

Marc said:
do I have to specify the field width, precisison etc.
for every object output new?
Yes.

Isn't there a way to set those constantly on a stream?

What do you mean constantly? FOr a type?
 
M

Marc Schellens

Attila said:
What do you mean constantly? FOr a type?

I mean for example setting the stream permanetly to scientific output.
Or to a specific field width.
There are some default values used anyway (eg. decimal output). These I
want to change.

marc
 
A

Attila Feher

Marc said:
I mean for example setting the stream permanetly to scientific output.
Or to a specific field width.
There are some default values used anyway (eg. decimal output). These
I want to change.

Some setting has a default (it is sticky, so to say) some does not. You
will need to see Josuttis or Langer&Kraft:

http://www.amazon.com/exec/obidos/ASIN/0201379260/

http://www.amazon.com/exec/obidos/tg/detail/-/0201183951/

I rarely use those modifiers myself, so I don't know them by hearth (and the
books aren't here).
 
M

Marc Schellens

osmium said:
Marc Schellens writes:




IIRC precision *is* persistent and width is not and can not be persistent.
I don't know what etc. includes so I am reluctant to comment on that. But,
in general, width is the primary offender to what you want.

thanks for the reply

etc is:

hex, oct, dec
uppercase, nouppercase
scientific, fixed
left, internal, right

And as I am asking:
is there a automatic scientific/fixed setting depending upon the
value (I think in printf it was %g but not sure)

Is there a way to have integers a minimum length padded with 0 from the
left?

thank you once more,
marc
 
G

Gary Labowitz

Marc Schellens said:
Is there a way to have integers a minimum length padded with 0 from the
left?

IIRC, all the manipulators are sticky except setw which must be specified
for each field. This allows you to insert variously sized fields into the
stream.
For the padding, use setfill('0') and preset right for the field. I think
that will do it.
#include <iostream>
#include <iomanip>

int main( )
{
int i = 32767;
std::cout << std::right << '$' << std::setfill('0');
std::cout << std::setw(20) << i << std::endl;
return 0;
}
Produces:
$00000000000000032767
 
O

osmium

Marc said:
do I have to specify the field width, precisison etc.
for every object output new?
Isn't there a way to set those constantly on a stream?

IIRC precision *is* persistent and width is not and can not be persistent.
I don't know what etc. includes so I am reluctant to comment on that. But,
in general, width is the primary offender to what you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top