79

\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.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434

6 Answers6

52

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

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
39

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
Vladimir
  • 170,431
  • 36
  • 387
  • 313
  • 8
    It's implementation-dependent in the sense that the way it is processed is up to the application/device receiving it, not the C++ program, which should just write it to the appropriate stream. – Fred Foo Dec 02 '10 at 12:45
  • It's not really obsolete, as there are still circumstances where you will write (extended) ASCII directly to a printer, for example when using receipt printers. It's not something you will need to use in a terminal, though. – Andrea May 27 '20 at 13:47
17

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

Tim Robinson
  • 53,480
  • 10
  • 121
  • 138
  • 5
    ^L formfeed is utilized to this day as a section-separator in plain text files, such as source code for computer-programming languages. When a text file gets lengthy and the first, say, 568 lines are one kind of thingy and the next 729 lines are a different kind of thingy, then often we put a ^L formfeed character at the beginning of line 569, often giving the ^L formfeed character its own line. Sometimes ^K vertical-tab and ^L are utilized together in this section-separator scheme with ^K for separating minor sections and ^L for separating major sections. – Andreas ZUERCHER Dec 14 '17 at 03:12
10

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

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

Roddy
  • 66,617
  • 42
  • 165
  • 277
4

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)

jv110
  • 353
  • 2
  • 13
-1

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

Output

Hello
     Goodbye
jony tony
  • 20
  • 3
  • This is not really the case for `\f`. This describes the vertical tab, e.g. `\v` (not sure if c++ has this). It could be the case that the form feed (next page) is interpreted this way in a terminal or whatever. See also [CB Bailey's answer](https://stackoverflow.com/a/4334399/2648551). – colidyre May 05 '19 at 09:22