Thread: cin.get() or system("pause")?

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    72

    cin.get() or system("pause")?

    hi

    when i want to stop the dos window should i use cin.get() or system("pause")?

    in C i used getchar() or system("pause") but what's the best in C++?

    thanks in advance

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Depends on your definition of "best".

    getchar() (in C or C++) or cin.get() (C++ only) are guaranteed to give intended behaviour.

    system("pause") is not actually guaranteed to work - in either C or C++.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    72
    Quote Originally Posted by grumpy View Post
    Depends on your definition of "best".

    getchar() (in C or C++) or cin.get() (C++ only) are guaranteed to give intended behaviour.

    system("pause") is not actually guaranteed to work - in either C or C++.
    thanks for your help

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.get() curiosity
    By lilrayray in forum C++ Programming
    Replies: 3
    Last Post: 09-03-2006, 10:07 PM
  2. cin.get() problem
    By Cilius in forum C++ Programming
    Replies: 20
    Last Post: 07-28-2005, 05:32 PM
  3. cin.get();
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2005, 07:51 AM
  4. cin.get() aint working.
    By Blips in forum C++ Programming
    Replies: 19
    Last Post: 01-17-2005, 06:55 PM
  5. Problems using while loop with cin.get()
    By Arooj in forum C++ Programming
    Replies: 4
    Last Post: 11-28-2004, 01:58 AM