manipulator persistence in streams

N

noone

Something I've noticed has me annoyed.

consider this


ostream o;

o << scientific << setw(15) << setprecision(5) << right <<
a << b << c << endl;

on some platforms a, b, and c are all formatted according to the field
widths specified and other times (a) is the only variable that maintains
the requested justification and field width.

I can understand something like


o << scientific << setw(15) << setprecision(5) << right << a;
o << b << c << endl;

throwing out the field information but I'm not seeing any consistency
across applications.

Aren't manipulators suppose to be persistent until overridden, especially
in one statement as in my first example?
 
V

Victor Bazarov

noone said:
Something I've noticed has me annoyed.

consider this


ostream o;

o << scientific << setw(15) << setprecision(5) << right <<
a << b << c << endl;

on some platforms a, b, and c are all formatted according to the field
widths specified and other times (a) is the only variable that
maintains the requested justification and field width.

I can understand something like


o << scientific << setw(15) << setprecision(5) << right << a;
o << b << c << endl;

throwing out the field information but I'm not seeing any consistency
across applications.

Aren't manipulators suppose to be persistent until overridden,
especially in one statement as in my first example?

I couldn't find any wording in the Standard to support this, but in
Josuttis' "The C++ Standard Library" he mentions that manipulators
with values (like setw or setprecision) only affect the next output
operation. The other type (right, scientific) are flag type manips
and they should stick, IIUIC.

V
 
N

noone

I couldn't find any wording in the Standard to support this, but in
Josuttis' "The C++ Standard Library" he mentions that manipulators
with values (like setw or setprecision) only affect the next output
operation. The other type (right, scientific) are flag type manips
and they should stick, IIUIC.

I guess that would explain the difference but I swear that I've seen
setw() and the like survive multiple statements in my foggy memory...must
have been bugs in the GNU implementations I used. Wouldn't be the first
time.

thanks!
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top