ostream question

This is a discussion on ostream question within the C++ Programming forums, part of the General Programming Boards category; How exactly does the ostream print out character on the screen without being OS specific? Or does the OS just ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    266

    ostream question

    How exactly does the ostream print out character on the screen without being OS specific? Or does the OS just read the characters from the stream and print them out themselves?

    Any help would be appreciated.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by lruc View Post
    How exactly does the ostream print out character on the screen without being OS specific? Or does the OS just read the characters from the stream and print them out themselves?

    Any help would be appreciated.
    It doesn't. Eventually, deep in the bowels of ostream, it has to call an OS API to do its job.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Not 100% sure but I would expect that compilers for different OS's have a different implementation of these things.

    As I understand it, being portable means that you can compile the exact same code for different platforms, but it doesn't mean that the compiler wouldn't implement your program in completely different ways.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    Thanks both of you. That is a question I have had for a long time. If could ask one more question that would be helpful. Does cin work the same way?

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Almost everything that does any kind of I/O has to call an API in the OS because it needs to access hardware to do it. Even malloc() calls an API (i.e. HeapAlloc() in Windows).

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The point of the standard I/O library is to hide the platform differences from the programmer. So the library is system-specific, but because it offers the same interface everywhere, you don't need to care.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    So the standard libraries arent always the same(i\o specificly)? If so then why does Bjarne Stroustrup give just one person credit?(not sure who)

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    The standard group define how the libraries work and the interface they have, but each compiler vendor implements these libraries themselves (ie, write all the code).
    So each compiler has its own library, but they work in the same way. So as a C++ programmer, you can use the libraries, despite what compiler it is, and know the result to be the same everywhere it's compiled.

    And it's I/O, not I\O.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    Thanks for all the answers. That cleared alot of things up.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And the person Bjarne credits for the iostreams library would be the guy who came up with the original interface. Then there's the guy who came up with the STL idea of containers, iterators and algorithms. And then there's the many people on the standards committee who refined those interfaces.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  2. ostream and istream
    By xddxogm3 in forum C++ Programming
    Replies: 2
    Last Post: 10-20-2003, 07:36 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 12:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21