Navigation

The definitions for the terms "cin" and "cout" in C++

In C++, cin and cout are standard character-based stream objects used for input and output, respectively. They are two members of a family of related standard stream objects
The definitions for the terms "cin" and "cout" in C++

In C++, cin and cout are standard character-based stream objects used for input and output, respectively. They are two members of a family of related standard stream objects:
  • cout
    An output stream (ostream) used for output to the equivalent of C’s stdout (standard output), which may be the console display or a file.
  • cerr
    An output stream (ostream) used for error output to the equivalent of C’s stderr (standard error), which may be the console display or a file. Unlike cout and clog, cerr is not buffered. Everything written to cerr is immediately written.
  • clog
    An output stream (ostream) used for logging output to the equivalent of C’s stderr (standard error), which may be the console display or a file.
  • cin
    An input stream (istream) used for input from the equivalent of C’s stdin (standard input), which may be the console keyboard or a file.
For wide characters, there are equivalents: wcout, wcerr, wclog, and wcin. The standard refers to these as “wide stream objects” and the streams in the above bulleted list as “narrow stream objects.”
In Stroustrup’s The Design and Evolution of C++, we have the following definitive meaning of the c prefix in these stream names:
“The c in the names of the standard I/O streams cout, cin, etc., stands for character; they were designed for character-oriented I/O.”
Contrary to popular belief/hope, the c was not meant to refer to console. While the default behavior of these streams is to interact with a text-based console, I/O redirection and piping are frequently used, so these stream objects allow data to be transferred to/from temporary and permanent files, not just the console.

>> Also you can read: How can you learn C and C++

مشاركة

أضف تعليق:

0 comments: