Streams: Predefined Streams
Applies To: C++Builder 1 or higher
Category: C++ Language
- The following predefined standard streams are automatically opened when the programs starts:
-
- cin : controls input
- cout: controls output
- cerr: controls error output
- clog: controls log output (buffer associated with cerr)
-
- There're also the corresponding wide character versions: wcin, wcout, wcerr and wclog.
-
- For example, to display text on the screen, use cout with the << operator:
-
- cout <<< "This is a text";
- cout <<< "\nThis is a number: " <<< 5;
-
- Escape sequences
- You can use the backslash to insert special characters:
· \a: Bell
· \b: Backspace
· \n: New line
· \t: Horizontal tab
· \\: Backslash
· \?: Question mark
· \': Single quotation
· \": Double quotations
-
- To read data from the keyboard, use cin with the >> operator. For example:
-
- int number;
- cout <<< "Enter number: ";
- cin >> number;
- cout <<< "Your number is: " <<< number;
-
- In order to use these streams, you must include the appropriate header and namespace.
C++Builder Developer's Network
Copyright © Yoto Yotov