473,756 Members | 9,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change the length of "\t"?

Hi,

It is possible to change the length of "\t" to a number other than 8.

std::cout << "\t";

Thanks,
Peng
Jul 14 '08 #1
25 30975
"Peng Yu" <Pe*******@gmai l.comwrote in message news:ad******** *************** ***********@59g 2000hsb.googleg roups.com...
Hi,

It is possible to change the length of "\t" to a number other than 8.

std::cout << "\t";

Thanks,
Peng
'\t' is a character with the decimal value of 9 if the ASCII coding is used. It has the same size as any other character.
"\t" is an array of two characters, '\t' and 0.
If you write it to a file and make a dump, you will see it.
What a terminal or printer does when it receives this character is not a C++ topic. Consult you terminal or printer manual.
Jul 14 '08 #2
On Jul 14, 7:24 am, Peng Yu <PengYu...@gmai l.comwrote:
It is possible to change the length of "\t" to a number other than 8.
std::cout << "\t";
The length of "\t" had better be two on any conforming C++
system. This goes back to the very beginnings of C, and is so
simple and basic that I find it almost inconceivable that a
compiler would get it wrong.

The value of the two bytes on my systems are 9 and 0, which is
almost universal today on everything but mainframes. (The
standard requires the second byte to be 0. The first byte will
be 5, however, on an IBM mainframe.)

So where is your 8 coming from?

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 14 '08 #3
Peng Yu wrote:
Hi,

It is possible to change the length of "\t" to a number other than 8.

std::cout << "\t";
Dear Peng,

'\t' is a character (tab), and the formatting of this character changes
according to the viewer you are using, it's not a problem of the
language. Printed on console it usually visualised with a number of
spaces that align to the next column which is divisible by 8, but this
can easily change and there is no standard or guarantee on that. If you
want properly formatted output, you'd rather rely on white spaces, that is:

cout << " hello," << endl;
cout << " world!" << endl;

Best,

Zeppe
Jul 14 '08 #4
On 2008-07-14 01:24:19 -0400, Peng Yu <Pe*******@gmai l.comsaid:
Hi,

It is possible to change the length of "\t" to a number other than 8.

std::cout << "\t";
Putting '\t' into an output stream simply writes a tab character. It's
up to whatever is interpreting the stream to handle the tab. If you
write to a file and load that file into a text editor, the tab will be
expanded to whatever width your text editor is set for. If you display
the file on your terminal, the tab will be expanded to whatever width
your terminal is set for. There's no direct way to control either of
those from the program that writes the file.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jul 14 '08 #5
On Jul 14, 2:23 am, "Fred Zwarts" <F.Zwa...@KVI.n lwrote:
"Peng Yu" <PengYu...@gmai l.comwrote in messagenews:ad* *************** *************** ***@59g2000hsb. googlegroups.co m...
Hi,
It is possible to change the length of "\t" to a number other than 8.
std::cout << "\t";
Thanks,
Peng

'\t' is a character with the decimal value of 9 if the ASCII coding is used. It has the same size as any other character.
"\t" is an array of two characters, '\t' and 0.
If you write it to a file and make a dump, you will see it.
What a terminal or printer does when it receives this character is not a C++ topic. Consult you terminal or printer manual.
Sorry for the confusion. I meant how to display it with other than 8
white spaces. I found the command 'less' has an option to change that
number from 8 to something else. Let me know if you have any better
solution.

Thanks,
Peng
Jul 14 '08 #6
James Kanze wrote:
On Jul 14, 7:24 am, Peng Yu <PengYu...@gmai l.comwrote:
>It is possible to change the length of "\t" to a number other than 8.
>std::cout << "\t";

The length of "\t" had better be two on any conforming C++
system. This goes back to the very beginnings of C, and is so
simple and basic that I find it almost inconceivable that a
compiler would get it wrong.

The value of the two bytes on my systems are 9 and 0, which is
almost universal today on everything but mainframes. (The
standard requires the second byte to be 0. The first byte will
be 5, however, on an IBM mainframe.)

So where is your 8 coming from?
I believe the OP meant to describe the desire to designate a different
set of positions (number of spaces) which outputting the TAB character
skips. I don't believe C++ defines that at all, it's the characteristic
of the device with which the output is associated.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 14 '08 #7
On Mon, 14 Jul 2008 10:14:15 -0700, Peng Yu wrote:
On Jul 14, 2:23 am, "Fred Zwarts" <F.Zwa...@KVI.n lwrote:
>"Peng Yu" <PengYu...@gmai l.comwrote in
messagenews:ad 461c8f-4117-4681-
ba************* **@59g2000hsb.g ooglegroups.com...
Hi,
It is possible to change the length of "\t" to a number other than 8.
std::cout << "\t";
Thanks,
Peng

'\t' is a character with the decimal value of 9 if the ASCII coding is
used. It has the same size as any other character. "\t" is an array of
two characters, '\t' and 0. If you write it to a file and make a dump,
you will see it. What a terminal or printer does when it receives this
character is not a C++ topic. Consult you terminal or printer manual.

Sorry for the confusion. I meant how to display it with other than 8
white spaces. I found the command 'less' has an option to change that
number from 8 to something else. Let me know if you have any better
solution.
As numerous posters have told you, that has *absolutely nothing* to do
with C++ and everything to do with how some particular program (e.g.
`less') chooses to display the '\t' character. If you want some
particular program to display '\t' differently, then consult the
documentation or some forum for that program. It is off-topic here, end
of.

--
Lionel B
Jul 15 '08 #8
On Jul 14, 10:22 pm, Victor Bazarov <v.Abaza...@com Acast.netwrote:
James Kanze wrote:
On Jul 14, 7:24 am, Peng Yu <PengYu...@gmai l.comwrote:
It is possible to change the length of "\t" to a number
other than 8.
std::cout << "\t";
The length of "\t" had better be two on any conforming C++
system. This goes back to the very beginnings of C, and is
so simple and basic that I find it almost inconceivable that
a compiler would get it wrong.
The value of the two bytes on my systems are 9 and 0, which
is almost universal today on everything but mainframes.
(The standard requires the second byte to be 0. The first
byte will be 5, however, on an IBM mainframe.)
So where is your 8 coming from?
I believe the OP meant to describe the desire to designate a
different set of positions (number of spaces) which outputting
the TAB character skips. I don't believe C++ defines that at
all, it's the characteristic of the device with which the
output is associated.
Well, he's confirmed that, but I'll admit that the idea didn't
even occur to me. Horizontal tab is a character like any other,
and how the display device reacts to it is very, very dependent.
Practically speaking, a de facto standard of one tab stop every
eight columns has established itself today, but historically, it
really was anything goes, with the print head advancing to the
next position where someone had "configured " a tab stop (and on
some printers, the configuration consisted of moving mechanical
pieces on the printer). In the early Fortran days, 7, then
every four or five, or else only 7 and 72, were common.

Today, as I said, the de facto standard is 8, and IMHO, setting
it to anything else is more or less the equivalent of defining
operator+ to do subtraction. I rather fear that I'm not widely
followed in this opinion, however, as I am constantly running
into text which expects it to be every 2, every 3 or every 4.
Pragmatically, you can more or less assume that '\t' means
display some random number of blanks. Even if you count on 8,
and program accordingly, your output will be messed up when
someone does a diff (which inserts 2 extra characters at the
start of each line) or a grep (which inserts the filename at the
start of each line). (Historically, '\t' was used in text files
as a simple form of compression. Today, for small files, it
doesn't matter, and for big files, gzip or bzip2 are a lot more
effective. And the use of '\t' instead of spaces can interfere
with the algorithms used by gzip or bzip2, and result in less
compression.)

Anyway, the correct solution if you want to position at a
specific place in the line is to output an appropriate number of
spaces (std::setw() can help here), and not to use '\t'. The
only time you should output a '\t' is when you want a tab
character in the text, say for some external program (e.g.
make, which requires tabs in some cases), or to allow the user
to indent according to his personal preferences.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 15 '08 #9
On Tue, 15 Jul 2008 01:42:37 -0700, James Kanze wrote:
On Jul 14, 10:22 pm, Victor Bazarov <v.Abaza...@com Acast.netwrote:
>James Kanze wrote:
On Jul 14, 7:24 am, Peng Yu <PengYu...@gmai l.comwrote:
>It is possible to change the length of "\t" to a number other than
8.
[...]
Today, as I said, the de facto standard is 8, and IMHO, setting it to
anything else is more or less the equivalent of defining operator+ to do
subtraction. I rather fear that I'm not widely followed in this
opinion,
Certainly not by me! The first thing I do when configuring an editor for
programming (anything) is to change the displayed TAB width to 4 (I might
also convert TABs to spaces, but that's not always an option). I've
always found 8 spaces makes code less readable and takes up an
inconvenient amount of horizontal space.

[...]

--
Lionel B
Jul 15 '08 #10

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

Similar topics

43
5124
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is relative NOT to the immediate script that is including it, but is relative to the top-level calling script. In practice, this means that you have to constantly worry and adjust paths in includes, based on the startup scripts that call these...
2
2940
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table driven. The regex would include if/then/else type logic, and would like my script to conditionally execute the logic. -- http://www.dbForumz.com/ This article was posted by author's request
81
7337
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
8
7598
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
8
3618
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n <br>mais pour avoir des resultats probant il faut pas faire les mariolles, comme le &quot;fondateur&quot; de bvs
2
4004
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down arrow and you see the entries in a dropdown. But how would I control this thing from javascript? Here is the HTML: <div class="selection" style="top:0; left:89; width:159; height:21;"
5
3686
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
1
2845
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. 1)<tm:bom-expression>{Conf.getEquityConfLookupFields().getEventFieldText(&quot;AdditionalDisruption&quot;,&quot;Change in Law&quot;)}</tm:bom-expression> 2)07:41:08 Default ( call ( . ( call ( . Conf getEquityConfLookupFields ) ) getEventFieldText ) ( , AdditionalDisruption Change inLaw ) ) value=Not applicable Can you please...
4
4214
by: thaytu888888 | last post by:
Here is my codes in aspx page: <td colspan="2" class="main_menu" runat="server" onclick='toggleDisplay(<%#Eval("description")%>);'><%#Eval("description")%></td> Here is in "View source": onclick="toggleDisplay(&lt;%#Eval(&quot;description&quot;)%>);">Administrator Functions</td> When putting <%#Eval('description')%> in <td> tag, it understand & show the correct value, but when in onclick='toggleDisplay(<%#Eval("description")%>);'> it didn't...
2
37794
by: jmash | last post by:
Suppose I have the following string whch is part of an xml string: String s= "Script Id=&quot;Test&quot; " And I need to get s= "Script Id="Test" " Can anyone tell me how this can acheived? Thanks, jmash
0
10062
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9901
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9878
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9728
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6551
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5322
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2694
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.