Thread: A problem

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    96

    A problem

    Hi,

    I have made a small program and have added system("pause");
    at the end of the program file.

    I wanted to know that is it necessary that we should add this "system("pause"); at the end of a program?

    When do we actually have to use this?

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by student111
    I wanted to know that is it necessary that we should add this "system("pause"); at the end of a program?
    It isn't.

    Quote Originally Posted by student111
    When do we actually have to use this?
    Never, except in the special case when you actually have to invoke a "pause" command for some exceedingly special reason, in which case you won't need to ask because you already know. Refer to this article on keeping the console window open.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    56
    I prefer using:

    Code:
    std::cin.ignore(); //ignores any information currently waiting to be gathered such as enters etc
    std::cin.get(); //requests user input. This will pause your program
    It's an extra line of code, but it avoids using system commands.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem passing argument into function, basic problem
    By tsdad in forum C++ Programming
    Replies: 7
    Last Post: 05-22-2013, 12:09 PM
  2. Replies: 2
    Last Post: 01-06-2013, 07:49 AM
  3. Replies: 1
    Last Post: 12-07-2012, 10:00 AM
  4. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM