473,396 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

setfill('\t')

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

Nov 22 '05 #1
5 6776

Angel Tsankov 写道:
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


no way ,pls,~_~

Nov 22 '05 #2

"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
Nov 22 '05 #3

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:vv*****************@newsread3.news.pas.earthl ink.net...

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';


With this format, the 'setw()' calls are no longer needed.

std::cout << '\t' << 1.23 << '\n';
std::cout << '\t' << 12.23 << '\n';

-Mike
Nov 22 '05 #4
I agree that output containing \t characters is not portable.
However, I'm currently using tabs to indent source code, since this way
it is managed somewhat easier with VIsual Studio. I need to produce
pieces of such code automatically, that's why I started the topic. Of
course, I've considered the use of spaces instead of tabs for
indentation in order to avoid the portability problem (even across
applications), but since the tools I use have options to specify the
tab width, I decided to use tabs.
Is this the case with tabs on other OS's? Do users have any way to
specify tab width?

Nov 22 '05 #5

"Angel Tsankov" <Bi****@abv.bg> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I agree that output containing \t characters is not portable.
However, I'm currently using tabs to indent source code, since this way
it is managed somewhat easier with VIsual Studio. I need to produce
pieces of such code automatically, that's why I started the topic. Of
course, I've considered the use of spaces instead of tabs for
indentation in order to avoid the portability problem (even across
applications), but since the tools I use have options to specify the
tab width, I decided to use tabs.
If you only intend to display that output on systems
with the same tab behavior (whether default or configured),
that's not a problem.
Is this the case with tabs on other OS's?
Some might allow one to configure tab behavior. Others might not.
Also some applications have configurable tab behavior.
Do users have any way to
specify tab width?


Visual Studio does.

Note: Whatever systems or editor applications you use, when posting code
to Usenet, please convert tabs to spaces in your code (specifically
because of what I mentioned: not everyone's display will render tabs
the same way, and this is especially a problem for those with displays
which simply ignore tabs; it destroys all indenting, making the code
much less readable).

If the editor you're using to write code doesn't have the capability
of converting tabs to spaces, there are many free utilities on the
net which can do that. Google can find them.

-Mike
Nov 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Philip Goisman | last post by:
Hi, Hope someone can help. I have the following c++ program which compiles fine in gcc2.96, but won't compile in gcc3.2.2: //FMain.cpp #include <stdlib.h> #include <stdio.h> #include...
2
by: Siegfried Heintze | last post by:
How do I use a template to write these friend functions once? The are nearly identical. Also, why does wcout << L'A'; print 65 instead of a character? Thanks, Siegfried struct DVDDeltaTime{ //...
10
by: Mathieu Malaterre | last post by:
Hello, I am trying to get rid a of sprintf in a c++ code, but I tried in several ways and couldn't figure out how to change: uint16_t group, uint16_t element; sprintf(buffer, "%04x|%04x",...
13
by: Jacek Dziedzic | last post by:
Hello! I have a piece of code that needs to display a formatted table of pointers using streams, with the pointers represented as hex values. It looks more or less like this: #include...
56
by: oLgAa25 | last post by:
I have the following question, I am trying to read from a file and output to another file. But I am not getting exactly the expected output. Can anyone help please! using namespace std;
31
by: Martin Jørgensen | last post by:
Hi, I've had a introductory C++ course in the spring and haven't programmed in C++ for a couple of months now (but I have been programmed in C since january). So I decided to do my conversion...
3
by: uche | last post by:
Please give me some feed back on this issue: Here is the complier error: hexdmp.cpp: In function `void output(unsigned char, int, bool&)': hexdmp.cpp:133: error: invalid types `unsigned char'...
5
by: ggloadi | last post by:
#include<iostream> #include<iomanip> using namespace std; class Currency { public: Currency(double v = 0.0) { unit = v;
2
by: Steven Woody | last post by:
Here is the code, uint16_t n1, n2; ... std::ostringstream os; os << "(" << std::hex << std::setw(4) << std::setfill('0') << n1 << "," << std::setw(4) << std::setfill('0') << n2 << ")"; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.