"Angel Tsankov" <Bi****@abv.bg> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Is there any way to I can make sensible use of the tab character to
fill spaces in a right-justified display so that code like this
using namespace std;
cout
<< setiosflags( ios::fixed )
<< setw( 6 )
<< setfill( '\t' )
<< setprecision( 2 )
<< 1.23
<< endl
<< setiosflags( ios::fixed )
<< setw( 6 )
<< setfill( '\t' )
<< setprecision( 2 )
<< 12.23
<< endl;
produces
[\t]1.23
[\t]12.23
instead of
[\t][\t]1.23
[\t]12.23
'setfill()' will cause subsequent output controlled by
'setw()' to 'pad' *every* unused character position encompassed
by the field width. So e.g. with a width of 6 and output of
1.23, you'll get two \t characters (or whatever the current
'setfill()' character is).
Also note that the specific behavior of \t will vary among
devices. (Might move current output position by four characters,
or eight, or none, etc. I.e. appearance of output containing
\t characters is not 'portable')
If you want to start your output at a given 'column' (whether
the result of a tab or a specific number of spaces), and left
justify it:
std::cout << std::left << std::setprecision(2);
std::cout << '\t' << std::setw(6) << 1.23 << '\n';
std::cout << '\t' << std::setw(6) << 12.23 << '\n';
/* (std::left is declared by <ios> )*/
(Note that the effects of stream manipulators remain until
specifically changed, with one exception: setw(), which is
automatically reset to setw(0) after each insertion. IOW
you don't need to repeat e.g. setprecision if the current setting
is appropriate.
-Mike