Jump to content
  • Advertisement
Sign in to follow this  
CJWR

what is cout and cin (c++)

This topic is 4768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!