C++ 转义序列 \f - 换页 - 它到底是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4334370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:08:45  来源:igfitidea点击:

Escape sequence \f - form feed - what exactly is it?

c++escaping

提问by Armen Tsirunyan

\fis said to be the form feed. \tis a tab, \ais a beep, \nis a newline. What exactly is a form feed - \f? The following program

\f据说是form feed。\t是制表符,\a是哔声,\n是换行符。什么是换页 - \f?下面的程序

#include <iostream>
int main()
{
   std::cout << "hello\fgoodbye" << std::endl;  
}

prints hellothen a female sign(an upside down holy hand grenade:) and then goodbyeall on one line.

hello然后打印一个女性标志(一个颠倒的圣手榴弹:),然后goodbye全部打印在一行上。

采纳答案by CB Bailey

It skips to the start of the next page. (Applies mostly to terminals where the output device is a printer rather than a VDU.)

它跳到下一页的开头。(主要适用于输出设备是打印机而不是 VDU 的终端。)

回答by Vladimir

From wiki page

来自维基页面

12 (form feed, \f, ^L), to cause a printer to eject paper to the top of the next page, or a video terminal to clear the screen.

12(换页,\f,^L),使打印机将纸张弹出到下一页的顶部,或视频终端清除屏幕。

or more details here.

或更多细节在这里

It seems that this symbol is rather obsolete now and the way it is processed may be(?) implementation dependent. At least for me your code gives the following output (xcode gcc 4.2, gdb console):

这个符号现在似乎已经过时了,它的处理方式可能是(?)依赖于实现的。至少对我来说,您的代码给出了以下输出(xcode gcc 4.2,gdb 控制台):

hello
    goodbye

回答by Tim Robinson

If you were programming for a 1980s-style printer, it would eject the paper and start a new page. You are virtually certain to never need it.

如果您正在为 1980 年代风格的打印机编程,它会弹出纸张并开始新的一页。您几乎可以肯定永远不需要它。

http://en.wikipedia.org/wiki/Form_feed

http://en.wikipedia.org/wiki/Form_feed

回答by Roddy

It comes from the era of Line Printersand green-striped fan-fold paper.

它来自行式打印机和绿色条纹折叠纸时代

Trust me, you ain't gonna need it...

相信我,你不需要它...

回答by jv110

Although recently its use is undefined, a common and useful use for the form feed is to separate sections of code vertically, like so: enter image description here(from http://ergoemacs.org/emacs/emacs_form_feed_section_paging.html)

尽管最近它的用途未定义,但表单提要的一个常见且有用的用途是垂直分隔代码部分,如下所示:( 在此处输入图片说明来自http://ergoemacs.org/emacs/emacs_form_feed_section_paging.html

回答by jony tony

It's go to newline then add spaces to start second line at end of first line

它转到换行符,然后在第一行末尾添加空格以开始第二行

Output

输出

Hello
     Goodbye