no instance of std::cout
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: no instance of std::cout

  1. #1
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    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.

  2. #2
    Join Date
    Oct 2011
    Posts
    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,247

    Re: no instance of std::cout

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,632

    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?
    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

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  5. #5
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,247

    Re: no instance of std::cout

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center