Thread: dumb question about streams

  1. #1
    Registered User
    Join Date
    Mar 2004

    dumb question about streams

    im a little confused about how streams works

    ie.(with keyboard)

    how the data gets into input stream???...

    when i type from my keyboard something, automatically all the text goes to the input stream?? or just after when i type ie. "enter"??

    ie.(from files)
    when i use the ifstream object and pass the file name to the constructor
    all the text inside the file is automatically put in the input stream??
    or just when i start to read the file with ie. getline??

    please any help?? and excuse my poor english

  2. #2
    Stinking it up. StinkyRyan's Avatar
    Join Date
    Jun 2004
    I'm not sure if these links will give you the answer you are looking for, infact I'm not really sure how to answer what you're asking could be on part of your phrasing of the question but I'm going to place all the blame on my lack of knowledge. Try giving these a shot and reading them over. By the way I found them by searching on enjoy the reading.
    Last edited by StinkyRyan; 07-06-2004 at 07:10 AM.
    Because I can't.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Just use the [url] tag to force it into a link

  4. #4
    Registered User
    Join Date
    Mar 2004


    the links dont work for me
    by the way thanks for repplies

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Quote Originally Posted by terracota
    the links dont work for me
    by the way thanks for repplies
    the links work fine for me. try copying and parsting the url's into your browser.

    btw, re: "dumb question about streams"
    there is no such thing as a dumb question. If google cant satisfy your query than its always welcome at the cboard

  6. #6
    Registered User
    Join Date
    Mar 2002
    Here's a partial explanation, from my understanding.

    When the user strikes a key on the keyboard, the information is usually, but not always, echoed to/displayed on the screen. In addition, usually, but not always, the keystroke information is stored in an istream member buffer, called rdbuf, I believe. Keystrokes are stored in the input buffer until the user pushes the enter/new line key. When the enter/new line key is encountered, or the buffer is full, whichever comes first, the istream object empties the buffer using one of the istream methods--like get() or getline()--or operators--like >>--as indicated by the programmer in the code that is being processed. The way the istream methods/operators remove data from the input buffer differ in significant ways that can cause bugs in your program if you use more than one istream method/operator, unless you are familiar with the quirks. Unfortunately, there is no built in method for clearing the input buffer completely.

    I remember seeing a reference to a book dedicated to streams not too long ago if you want to buy a hardcopy, detailed description of the process. You can probably find it by doing a search of the board using stream or istreams as the search key. It was within the last month or so.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    There are two types of input: buffered, and non-buffered. Think of playing a video game, where as soon as you press a key, something happens. That is non-buffered input. Think of a prompt asking you for a name, which when you get around to hitting enter, does something else. That's a poor example of buffered input.

    Buffered input waits for you to press enter before something happens. Non-buffered doesn't. Now naturally you can emulate the effect of buffered input with non-buffered input. However, you cannot emulate non-buffered behaviour with buffered.

    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Mar 2004
    ok thanks a lot
    know i have a more clear idea how streams work.

    one more thing:

    when trying to write a user defines objet to a file how the reinterpret_cast converts the objet direction to a char pointer? ie:
    Car toyota;
    ofstream myFile("myFile.txt", ios::binary);
    myfile.write(reinterpret_cast<const char*>(toyota), sizeof(toyota);
    //whats the trick behind reinterpret_cast??
    //because toyota can have data members like char, int , double, etc, how is treated
    //this data to convert it to char???

    thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dumb I/O Performance Question
    By BENCHMARKMAN in forum C Programming
    Replies: 18
    Last Post: 02-24-2008, 06:26 AM
  2. dumb question?
    By davelair27 in forum C Programming
    Replies: 6
    Last Post: 10-11-2006, 06:10 AM
  3. Dumb question
    By dragon2309 in forum C Programming
    Replies: 18
    Last Post: 10-29-2005, 03:27 PM
  4. Dumb question time - Winsock & accept()
    By jdinger in forum Networking/Device Communication
    Replies: 5
    Last Post: 06-11-2005, 01:08 AM
  5. another dumb question - loop not working?
    By Captain Penguin in forum C++ Programming
    Replies: 8
    Last Post: 10-06-2002, 10:15 PM