Thread: Unable to pause program

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    1

    Question Unable to pause program

    Hello I have been programming for a few days now and I have runned inn to a little problem. the cin.get(); won't pause my program.

    I have tried to use cin.ignore(); above the cin.get() to make it pause but with no sucsess

    i have also tried to use
    system("pause");

    the compiler I use is called "Microsoft Visual c++ 2010"

    Code:
    #include "stdafx.h"
    
    
    #include <iostream>
    
    
    using namespace std;
    
    
    
    
    int main ()
    {
        cout << "Hello world\n";
        cout << "Here is 5: " << 5 << "\n";
        cout << " the manipulator endl writes a new line to the screen." <<
            endl;
        cout << " Here is a very big number:\t" << 70000 << endl;
        cout << " Here is the sum of 8 and 5:\t" << 8+5 << endl;
        cout << " Here's a fraction:t\t" << (float) 5/8 << endl;
        cout << " and a very very big number:\t" << (double) 700 * 700 <<
            endl;
        cout << "Don't forget to replace Jesse Liberty with your name...\n";
        cout << "shacko is a C++ programmer!\n";
    
    
        
        cin.get();
        return 0
    }

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    There's no semicolon after the "return 0". I don't know if this was a copy-paste error, but it's possible that you were just running the last successful build (presumably from before you inserted the cin.get()).

    If that is the issue, I'd recommend changing this setting for future use:
    In the Projects and Solutions options: Build and Run -> On Run, when build or deployment errors occur -> Prompt To Launch

    Then VS will bring a message box up if the build fails.
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    19
    You can type getchar();it does the same job.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The real question is, why do you want to pause the program? Launch it with Ctrl+F5 instead of just F5 and Visual Studio will keep the console open for you.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jan 2012
    Posts
    9
    i use. i dont know if they work very well but they do the job for me...maybe they will help you untill you learn a better method
    Code:
    cin.ignore();
    cin.get();

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    CornedBee just mentioned a better method right above your reply!
    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. Pause a C program without getch()
    By swgh in forum C Programming
    Replies: 4
    Last Post: 02-20-2006, 11:24 AM
  2. Why won't my program pause?
    By ladysniper in forum C++ Programming
    Replies: 4
    Last Post: 02-13-2006, 03:22 AM
  3. How do you pause a program?
    By Elite in forum C Programming
    Replies: 3
    Last Post: 03-14-2005, 07:45 AM
  4. pause program at console
    By datainjector in forum C# Programming
    Replies: 1
    Last Post: 03-27-2003, 12:36 AM
  5. How do I make my program pause
    By quiksilver9531 in forum C++ Programming
    Replies: 9
    Last Post: 01-23-2002, 07:38 PM

Tags for this Thread