-
September 24th, 2012, 10:28 AM
#1
no instance of std::cout
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.
-
September 24th, 2012, 11:00 AM
#2
Re: no instance of std::cout
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.
-
September 24th, 2012, 01:18 PM
#3
Re: no instance of std::cout
Originally Posted by aamir121a
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.
-
September 24th, 2012, 02:56 PM
#4
Re: no instance of std::cout
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?
-
September 25th, 2012, 10:34 AM
#5
Re: no instance of std::cout
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.
-
September 25th, 2012, 10:52 AM
#6
Re: no instance of std::cout
Originally Posted by aamir121a
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|