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

C++Escaping

C++ Problem Overview


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

C++ Solutions


Solution 1 - C++

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

Solution 2 - C++

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

Solution 3 - C++

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

Solution 4 - C++

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

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

Solution 5 - C++

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)

Solution 6 - C++

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

Output

Hello
     Goodbye

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArmen TsirunyanView Question on Stackoverflow
Solution 1 - C++CB BaileyView Answer on Stackoverflow
Solution 2 - C++VladimirView Answer on Stackoverflow
Solution 3 - C++Tim RobinsonView Answer on Stackoverflow
Solution 4 - C++RoddyView Answer on Stackoverflow
Solution 5 - C++jv110View Answer on Stackoverflow
Solution 6 - C++jony tonyView Answer on Stackoverflow