iostream questions

This is a discussion on iostream questions within the C++ Programming forums, part of the General Programming Boards category; hey, I'm switching from cstdio to iostream but am having problems finding documentation on what I want to learn. could ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    5

    iostream questions

    hey, I'm switching from cstdio to iostream but am having problems finding documentation on what I want to learn. could someone here tell me exactly what cin's sync() and clear() methods do? are they both of type void, do they take any parameters?

    thanks

    edit: I've also two questions about cout's flush method:

    1) why must the buffer be flushed and when is an appropriate time to do this?

    2) is it faster to use endl or "'\n'" with flush?
    Last edited by bryan; 05-18-2004 at 01:24 PM.

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    1) You wanna make sure that everything that needs to be printed on the screen is printed to the screen. Say you want to print a prompt for user to input something, you want the prompt to display otherwise users don't know what to do staring the black screen
    2) Just guessing: endl.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    "endl" will flush an output stream, "\n" will not.

    sync() is a member of basic_istream, which you can read about here.
    clear() is a member of basic_ios, which you can read about here.

    You might want to pick up a good standard C++ book if you don't already have one.

    gg

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Quote Originally Posted by Codeplug
    "endl" will flush an output stream, "\n" will not.
    gg
    The question was which one is faster?
    a) endl
    b) '\n' followed by flush
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    For standard output, the difference is most likely insignificant.
    For wirtting a text file with multiple megs, there may be some value added in letting the OS flush it's file buffers on it's own schedule. But probably not

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

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