Return to Topic Menu | Computer Science Main Page |  | Terms of Use

Output to the Screen

cout (pronounced "see-out") is not a Visual C++ command word, although it acts like one.  You will not see cout in the list of Command Words (or Keywords).  cout is an operator (just as addition or multiplication are operators) described in the header file iostream.h.  cout sends output to an output device, usually the screen.  The double arrows (<<) point the way (toward "out"), showing that the information is going "out" to the monitor.


The following is a table of escape sequences which can be used with cout:

Sequence Name Meaning
\n New line Moves to beginning of next line
\b Backspace Backs up one character
\t Horizontal tab Moves to next tab position
\a Alert Sounds a beep
\\ Backslash Displays an actual backslash
\' Single quote Displays an actual single quote
\" Double quote Displays an actual double quote
\? Question mark Displays an actual question mark

If you wish to use the ANSI code sheet to print "fancy" characters on the screen, you can place the code sheet's octal number after a backslash with a cout statement.  For example,
cout << "\3" ;            //prints a small heart on the screen. 


If you wish to use the ASCII code sheet to print "fancy" characters on the screen, use the following syntax:
cout<< char(228);    // prints the Greek letter sigma on the screen.


Tidbits of information about those pesky tabs:
1.  printing in the last column will force a new line.
2. the tab spacing is every 8 columns consistently starting with 1:
(9, 17, 25, 33, 41, 49, 57, 65, 73 . . . then go to 1)
3. tabbing beyond one line's "worth" will push the tabs into the same tabbing pattern on the next line starting with 1.
4.  tabbing takes you to the next available tab.
5. if you print in the "8th" column and then tab, tab will skip the next field and take you to the NEXT tab location.
6. tabbing without the use of \n, will simply continue in the same pattern.


 Return to Topic Menu | Computer Science Main Page |  | Terms of Use