Why there is never an instance of std::cout ever created. Before we use any object of C++ , like std::string mystring or std::vector<somedata> , std::ifstream mystream, you get the picture
we can use std::cout without going std::cout myconsolestream and then use it.
This is because cout is not a "type" so to speak...
The other things you mention are data types or structures, whereas cout is a code snipped inside the standard library which gets ran when you call it, you are not creating an instance of cout in this case.
Imagine it like a function beig called, not a constructor.
Why there is never an instance of std::cout ever created. Before we use any object of C++ , like std::string mystring or std::vector<somedata> , std::ifstream mystream, you get the picture
we can use std::cout without going std::cout myconsolestream and then use it.
std::cout is an instance of the std::ostream class. It is created before control enters the body of the main function.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
It's just as it always(?) has been. Compare with the low level I/O files stdin, stdout and stderr (http://msdn.microsoft.com/en-us/libr...=vs.110).aspx). Those files also exists and are open when main is entered without you having to do anything. Do you notice the similarity in the names by the way?
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Not before , however I can see now that you mentioned it , thank you all for post , one last thought , why std::cout and not anything else , is setup this way.
one last thought , why std::cout and not anything else , is setup this way.
You forgot about std::cin, std::cerr, std::clog and their wide I/O stream equivalents. A common characteristic is that they represent some kind of global state; you may find that other libraries likewise use such objects to store/model global state.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Bookmarks