打印在Windows控制台时所需的回车? [英] Carriage return required when printing to the console in Windows?

查看:178
本文介绍了打印在Windows控制台时所需的回车?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像只是把一个换行符是不够好,但我知道它应该是回车+换行。如果你不把回车,只用换行做任何事情发生可怕的?

It seems like just putting a linefeed is good enough, but I know it is supposed to be carriage return + line feed. Does anything horrible happen if you don't put the carriage return and only use line feeds?

这是ANSI C和不会被重定向到文件或其他任何东西。只是一个正常的控制台应用程序。

This is in ANSI C and not going to be redirected to a file or anything else. Just a normal console app.

推荐答案

Windows控制台得出假设的文件,或与此有关的实际,物理终端在同一行结束约定。它需要看到两个CR和LF正确移动到下一行。

The Windows console follows the same line ending convention that is assumed for files, or for that matter for actual, physical terminals. It needs to see both CR and LF to properly move to the next line.

这是说,有很多的ANSI C程序和控制台之间的软件基础设施。特别是,任何标准C库I / O功能要尝试做正确的事情,假设你允许它的机会。这就是为什么 fopen()函数的 T B 模式参数修饰符被定义。

That said, there is a lot of software infrastructure between an ANSI C program and that console. In particular, any standard C library I/O function is going to try to do the right thing, assuming you've allowed it the chance. This is why fopen()'s t and b modifiers for the mode parameter were defined.

使用 T (默认为最流,特别是标准输入标准输出),那么任何 \\ n打印转换为CRLF序列,情况相反的读取。要关闭该行为,使用 B 修改

With t (the default for most streams, and in particular for stdin and stdout) then any \n printed is converted to a CRLF sequence, and the reverse happens for reads. To turn off that behavior, use the b modifier.

顺便说一句,传统的终端迷上* nix中盒包括模拟的XTerm还需要两个CR和LF的DEC VT100。然而,在* nix的世界,从一个换行符到CRLF序列转换是在tty设备驱动程序处理所以大多数程序不需要了解它,而 T b 修改器都忽略了。在这些平台上,如果你需要一个tty发送和接收字符未经该修改,你需要仰视的stty(1)或系统调用它取决于

Incidentally, the terminals traditionally hooked to *nix boxes including the DEC VT100 emulated by XTerm also needs both CR and LF. However, in the *nix world, the conversion from a newline character to a CRLF sequence is handled in the tty device driver so most programs don't need to know about it, and the t and b modifiers are both ignored. On those platforms, if you need to send and receive characters on a tty without that modification, you need to look up stty(1) or the system calls it depends on.

如果您否则ANSI C程序是避免C库I / O控制台(可能是因为你需要访问控制台的字符颜色等属性),你那么是否需要发送CR与否将取决于Win32 API调用您正在使用发送字符。

If your otherwise ANSI C program is avoiding C library I/O to the console (perhaps because you need access to the console's character color and other attributes) then whether you need to send CR or not will depend on which Win32 API calls you are using to send the characters.

这篇关于打印在Windows控制台时所需的回车?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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