[try Beta version]
Not logged in

 
I/O streams & std namespace

Oct 22, 2020 at 8:38pm
Hi, I am trying to learn about the IO streams and have a question regarding that and std namespace. From this page It appears that all the streams inherit from ios_base, eg iostream, fstream etc. So I am wondering about the functions in these stream classes, for instance cout, (not sure if classified as a function) is it declared in the stream class or in std namespace, since i need to include iostream to use cout and include std namespace.

Oct 23, 2020 at 8:36am
cout, cin, cerr, clog are global variables that are defined in the std namespace.
Oct 23, 2020 at 11:46am
Ok so is it like, ostream is a class defined somewhere, and then in namespace std cout is declared as a global of type ostream?

And now that I think about it again, I know that cout if not a function because it is just the output stream.
Oct 23, 2020 at 12:23pm
Ok so is it like, ostream is a class defined somewhere, and then in namespace std cout is declared as a global of type ostream?

You are right.
If you want some more information:
https://stackoverflow.com/questions/33110526/how-does-stdcout-declaration-work
Oct 23, 2020 at 4:03pm
Thank you for the help, I will look into the link.
Topic archived. No new replies allowed.