what is cout and cin (c++)

Started by
4 comments, last by CJWR 18 years, 9 months ago
i used to think cout and cin were simply c++ op. words. than i learned more about c++ and fstream and thought they were like ifstreams and ofstreams, but dealing with the screen instead of a file. however, you need to declare a object of type ifstream or ofstream to use it. you don't have to declare an object known as cout of type istream however to use cout. so what are cout and cin? thanks.
Charles Reed, CEO of CJWR Software LLC
Advertisement
cin & cout are the objects ;]
They're externals

That is they're defined inside the std library
When you include the header you include the extern definition (kinda) so you're linked to them
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
To be precise cin/cout are global instances (in namespace std) of std::basic_i/o/iostream. std::basic_i/o/iofstream (std::i/ofstream are type aliases) are sub-types of std::basic_i/o/iostream that is why they are similar.
std::cin is an instance of std::istream and is linked to standard input.
std::cout is an instance of std::ostream and is linked to standard output.
std::cerr is an instance of std::ostream, is linked to standard error, and is not buffered. (to make sure anything you write to it shows up incase your program dies unexpectedly)
std::clog is an instance of std::ostream, is linked to standard error, and is buffered.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
pi=3.14
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
ah! so i was right, but iostream already declares them! thanks.
Charles Reed, CEO of CJWR Software LLC

This topic is closed to new replies.

Advertisement