G
genxtech
Is it possible to change how many characters are printed to the
standard output when "\t" is passed to cout?
standard output when "\t" is passed to cout?
Is it possible to change how many characters are printed to the
standard output when "\t" is passed to cout?
Is it possible to change how many characters are printed to the
standard output when "\t" is passed to cout?
'\t' is a single character. cout is output stream. If you want to pass
some other characters to cout, then pass.
I understand that it is a single character, but since it represents a
tab in the output stream... I was wondering if there is a parameter to
set in the<iostream> set of classes that allow for the manipulation
of how many characters are outputted ... regardless of the os that is
used, and with out hard coding the number of spaces.
red floyd said:Nope. It's system specific.
I understand that it is a single character, but since it represents a
tab in the output stream... I was wondering if there is a parameter to
set in the <iostream> set of classes that allow for the manipulation
of how many characters are outputted
used, and with out hard coding the number of spaces.
It also would
be rather difficult to implement: the internals of the ostream
would have to keep track at which position in a line it is to be
able to calculate into how many spaces a tab has to be converted.
But it's not so easy to do that since there are other characters
like '\b' ('backspace') that make things more interesting. Has
the internal line position counter to be decremented at a '\b'
or incremented? And what's about the '\a' ('bell')? Does it
count as a character? (Or should 'cout <<' try to make the
computer beep and not output it at all?) Like them '\t' is a
non-printable character that is used as a "signal" to whatever
is reading on stdout and it's that reader that only knows what
to do wih them.
But '\t' is just a single character, so it can only be output
as one character. There's another program that receives the
output from stdout and that gets the single tab character and
interprets it. This may e.g. a console program or a shell that
then expands the tab. Or stdout may have been redirected to a
file, and if you afterward check what's in the file (e.g. with
a hex editor) you will find that there's just a single '\t'
character. Only if you view that file with some program this
viewer progam will expand the tab into a number of spaces. So
the conversion of the tab doesn't happen during the 'cout <<'
but only when another program (which you don't know about from
within your progam) interprets the '\t'.
... regardless of the os that is
To achieve what you want '\t' would have to be converted already
in the 'cout <<' call, but that's not what's happening and I am
not aware of any possibility to get it to do that. It also would
be rather difficult to implement: the internals of the ostream
would have to keep track at which position in a line it is to be
able to calculate into how many spaces a tab has to be converted.
But it's not so easy to do that since there are other characters
like '\b' ('backspace') that make things more interesting. Has
the internal line position counter to be decremented at a '\b'
or incremented? And what's about the '\a' ('bell')? Does it
count as a character? (Or should 'cout <<' try to make the
computer beep and not output it at all?) Like them '\t' is a
non-printable character that is used as a "signal" to whatever
is reading on stdout and it's that reader that only knows what
to do wih them. So the most reasonable way seems to me to leave
the output alone and let the program that reads the output deal
with all that - it may have some options to tell it into how
many spaces a tab is to be expanded. If it doesn't you could
pipe the output through a program that does suitable tab re-
placement...
Regards, Jens
Is it possible to change how many characters are printed to the
standard output when "\t" is passed to cout?
As another note, it may not even be your OS that does this. I've
worked on dumb terminals where tabstops can be specified at the
terminal level -- Lear Siegler ADM-12.
.......
To achieve what you want '\t' would have to be converted already
in the 'cout <<' call, but that's not what's happening and I am
not aware of any possibility to get it to do that.
Is it possible to change how many characters are printed to the
standard output when "\t" is passed to cout?
On 10/2/2010 10:05 PM, genxtech wrote:
Nope. It's system specific. There's no guarantee that your system will
even convert tabs to spaces on output.
if a custom stream wants to virtualize \t it must do the same for all
control characters. In this case most of the questions are solved.
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.