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

流过昼夜 提交于 2019-12-17 08:54:36

问题


\f is said to be the form feed. \t is a tab, \a is a beep, \n is a newline. What exactly is a form feed - \f? The following program

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

prints hello then a female sign (an upside down holy hand grenade:) and then goodbye all on one line.


回答1:


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




回答2:


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.

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):

hello
    goodbye



回答3:


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.

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




回答4:


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

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




回答5:


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




回答6:


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

Output

Hello
     Goodbye


来源:https://stackoverflow.com/questions/4334370/escape-sequence-f-form-feed-what-exactly-is-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!