Thread: flush()?

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    106

    flush()?

    what is the flush() function defined in fstream.h?
    C++ Makes you Feel Better

    "Gravity connot be held reponsible for people falling in love"--Albert Einstein

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It makes sure that any data which is still in a buffer between your program and the actual file is actually written to that file.

    PS
    They're called manual pages

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    yeah, i was wondering that question, can you xplain it a little better?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    "Buffering", as you may already be aware, stores data in an array until one of two conditions occur. (Oversimplifying here, but it'll give you a "leg up" on what's taking place.)

    The first condition is an "overflow" of the buffer (array) which signals the compiler to "write" the contents of the buffer to the appropriate file. Simply put, the buffer is full and it's time to empty it.

    The second condition (the subject of this thread) is when the buffer is "flushed". This 'forces' the writing of the buffer contents to the appropriate file, typically, before the buffer is full.

    A trivial, but perhaps enlightening, example of implicit flushing is the "tie" between cout and cin.

    Code:
    std::cout << "Enter your age: ";
    std::cin >> age;
    Since the output stream is buffered, unless it were "flushed", the user wouldn't see the prompt, i.e. the buffer would hold our prompt message until the buffer was full.

    However, due to the tie between 'ostream' and 'istream', there is an implicit call, cout.flush(), that forces the message to be displayed before extracting data to the input stream.

    Buffering is actually a far more complicated topic than what I've attempted to give you here, but I hope this helps a little.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with input flush
    By KarrieWojo in forum C Programming
    Replies: 12
    Last Post: 12-29-2007, 02:38 AM
  2. endl - \n
    By Hugo716 in forum C++ Programming
    Replies: 8
    Last Post: 05-25-2006, 02:33 PM
  3. flush socket
    By Snip in forum Networking/Device Communication
    Replies: 17
    Last Post: 02-08-2005, 09:29 PM
  4. How do I print a pattern flush right?
    By Basia in forum C Programming
    Replies: 5
    Last Post: 06-11-2002, 07:15 AM
  5. Can someone xplain FLUSH in strings?
    By aspand in forum C Programming
    Replies: 9
    Last Post: 05-13-2002, 12:10 AM