what is cout and cin (c++)
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.
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
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement