有多少空格\\ t被认为是 [英] how many spaces are considered in \t

查看:157
本文介绍了有多少空格\\ t被认为是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么的空间的数量是在情况3不同
如何结果过得去\\ t字符影响。

why the number of space is different in case 3 how the result is getting effected by \t character.

( - )是指由空格(\\ T)

(-) refers space by (\t)

case 1
 void main()
    {
        int a,b;
        printf("%d",printf("hello%d\t",scanf("%d%d",&a,&b)));
    }

在这里输出> hello2-7

here the output is>hello2-7

case 2
 void main()
    {
        int a,b;
        printf("%d",printf("hello\t%d",scanf("%d%d",&a,&b)));
    }

在这里输出> HELLO-27

here the output is>hello-27

case 3
 void main()
    {
        int a,b;
        printf("%d",printf("\thello%d",scanf("%d%d",&a,&b)));
    }

在这里输出> -------- hello27
为什么在第三届情况下,有8个空格。

here the output is>--------hello27 Why in the 3rd case there are 8 spaces.

推荐答案

的终端程序将在每8列制表位 - 所以我期望输出这样的决定(我知道你的输出是一个有点不同 - 在下面讨论):

Most terminal programs will have a tab stop at every 8th column - so I'd expect output to be determined like this (I know your output's a little different - discussed below):

.                                column
.                                   1         2
input                      12345678901234567890
"%d",printf("hello%d\t"    hello2__7
"%d",printf("hello\t%d"    hello___27
"%d",printf("\thello%d"    ________hello27

要理解这一点,你必须了解你的(不必要的复杂)code的计算顺序。检查第一的printf 行...

To understand this, you have to understand the order of evaluation of your (unnecessarily complex) code. Examining the first printf line...

printf("%d",printf("hello%d\t",scanf("%d%d",&a,&b)));

以上,在参数的到的左手的printf 必须之后才能prepared打印任何东西本身,这些参数包括调用的右手的结果的printf 。那右手的printf 输出你好,参数个数 scanf函数从标准输入是2读,如果你输入的二,然后在选项卡,然后右手的printf 已完成输出,并返回7表示多少个字符它印,这是由左手打印的printf 。我所期望的标签带你到屏幕上的第9列,其中7之前提出两个空间,在这里,你的问题说你观察1.明确终端的作用有点不同,可能是考虑到8日,16日, 24日等字段为制表位。

Above, the arguments to the left-hand printf have to be prepared before it can print anything itself, and those arguments include the result of calling the right-hand printf. That right-hand printf outputs hello, the number of arguments scanf read from standard input which is 2 if you typed two, then the tab, then the right-hand printf has finished outputting and returns "7" to indicate how many characters it printed, which is printed by the left-hand printf. I would expect a tab to take you to the 9th column on screen, which suggests TWO spaces before the 7, where-as your question says you're observing 1. Clearly your terminal works a little different, probably considering the 8th, 16th, 24th etc. columns to be tab stops.

有是 \\ t TAB键......它是如何呈现的没有通用的跨pretation取决于终端软件或渲染设备,您正在使用(如一个xterm,VT220,VT100终端,MS-DOS命令行窗口,打印机,IDE,文本编辑器等)。

There is no universal interpretation of the \t TAB character... how it's rendered depends on the terminal software or rendering device you're using (e.g. an xterm, vt220, vt100 terminal, MS-DOS command window, printer, IDE, text editor etc.).

某些显示/打印/格式化程序会考虑那里是一个制表位每N个字符,其中N是常8,这样,如果通过的8列从发出第一列选项卡你带到9日,从9日至16日列选项卡,可到17等。但是,许多程序都会有方法来设置任意列标签的展示位置。如MS Word中的某些程序可以使用与标签之间的字符数停止变化的可变宽度字体:如果你的C ++程序打印您导入到Word中一些文字,您可能会发现它几乎是不可能制定出许多标签是如何需要得到输出所需的对齐方式 - 这是通常更容易只是把值之间的一个选项卡并更改您的制表位内的Word所以这一切看起来正常,还是坚持一个固定宽度字体如Courier

Some display/printing/formatting programs will consider there to be a tab stop every N characters, where N is often 8, such that if you issue a tab from the first column through to the 8th column you're taken to the 9th, a tab from the 9th to 16th column takes you to the 17th etc.. But, many programs will have ways to set arbitrary columns for tab placements. Some programs like MS Word can use variable-width fonts with which the number of characters between tab stops varies: if your C++ program prints some text that you import into Word you may find it practically impossible to work out how many tabs are needed to get the desired alignment of output - it's generally easier to just put one tab between values and change your tab stops inside Word so it all looks ok, or stick to a fixed-width font such as Courier.

C ++集成开发环境常常让你每制表位的列设置的值(N以上) - 4和8都是常见的设置,与8往往意味着你的源代码code缩进是制表和空格的组合,以达到预期的左侧列:这是一种带有凌乱天真的光标移动实现导航。很多人preFER设置插入空格时,标签是pressed选项,这样文件总是保存实际空间,并配有多种显示/打印软件pdictably显示更多$ P $。

C++ IDEs often let you set the value ("N" above) for columns per tab stop - 4 and 8 are both common settings, with 8 often meaning your source code indentation is a mix of tabs and spaces to reach the desired left-hand-column: that's kind of messy to navigate with naive cursor movement implementation. Many people prefer to set a "insert spaces when tab is pressed" option so the file is always saved with actual spaces, and displays more predictably with a wide variety of display/printing software.

这篇关于有多少空格\\ t被认为是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆