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

This is a discussion on cin.get() or system("pause")? within the C++ Programming forums, part of the General Programming Boards category; hi when i want to stop the dos window should i use cin.get() or system("pause")? in C i used getchar() ...

  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,262
    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%.

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    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, 05:55 PM
  5. Problems using while loop with cin.get()
    By Arooj in forum C++ Programming
    Replies: 4
    Last Post: 11-28-2004, 12:58 AM

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