Discussion: iomanip - alignment
Afficher un message
Vieux 18/10/2007, 23h51   #2
Maarten Kronenburg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: iomanip - alignment


"brekehan" wrote in message
> 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.
>


For the floating point you also may use setprecision(3) for 3 decimals after
the point:
cout << right << setw(6) << setprecision(3) << 0.123;


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