Discussion: iomanip - alignment
Afficher un message
Vieux 18/10/2007, 22h04   #1
brekehan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut iomanip - alignment

I can't seem to get the alignment to switch back and forth combined
with a set width. I tryed a search on this group and alot of googling,
but still can't deduce the problem.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
// using cout instead of ostream & operator << method, for example
purposes
// hardcoding values instead of class data for example purposes

cout << setiosflags(ios::fixed);

cout << left << setw(25) << "attribute name:";
cout << right << setw( 6) << 0.111;
cout << endl;

cout << left << setw(25) << "attribute name";
cout << right << setw( 6) << 0.123556;
cout << endl;

// etc etc

cout << resetiosflags(ios::fixed);

return 0;
}

The output seems to always be left aligned. I've also tryed using <<
setiosflags and << resetiosflags with the same results.

Can anyone clear this up for me? I hate to admit that I've forgotten
something so basic.

What is the lifetime of the differant iomanip members used here?
How are right and left alignments represented internally? i.e do you
need to reset left before using right and vica versa? or are they two
states of the same bit.

  Réponse avec citation
 
Page generated in 0,05815 seconds with 9 queries