the cin object which is a special instance of ostream ... cout a specialised instance of ifstream. |
You have it backwards. cin is an
istream and cout is an
ostream.
On UNIX systems, I/O is handled through file descriptors. These are small integers that identify an I/O mechanism. Just as a C++ istream can be a stringstream or an ifstream or any other sort of stream, a file descriptor can be associated with a terminal, a file, a pipe, a tape drive, a network connect, etc. The big difference is that file descriptors are all handled at the OS level. It's pretty clever, and it was all conceived nearly 50 years ago.
When a program starts file descriptor 0 is stdin, FD 1 is stdout, and FD2 is stderr. Exactly what those fd's point to depends on what they were set to by the program that launched your program (like the shell).
If it's a C++ program, the startup code associates fd 0, 1, and 2 with cin, cout and cerr also. Note that I said "startup code." That's the real entry point to the program: the code that the OS calls when it starts a program. In a C++ program, it's a bit of library code that creates cin/cout,cerr, calls the constructors on file-scope variables and does whatever other initialization is needed. When it's done, it calls main().