Jump to content
xisto Community
Sign in to follow this  
Feelay

Pause A Command Prompt After Execution?

Recommended Posts

sorry, title should be "Pause a console program after execution".

Hey!

ok.. when I created this thread, I needed help, but now I solved the problem, and here is the solution.

my problem was, that I couldn't make my application pause. It just executed, and then closed. so here is my old code.


#include "stdafx.h"#include "iostream"#include "stdio.h"using namespace std;int main(){	cout << "Hello World!" << endl;	char name;	cout << "Write your name, please: ";	cin >> name;	cout << "Hi " << name << "! Welcome, And Thank You For Trying My First Software :D"<< endl;	cout << "Press ENTER to continue..." << endl; 	cin.get(); return 0;}

And here is what I did.

after the
cin >> name;

I added this:
cin.ignore();

Now this will allow me to add the:

cin.get();
before the "return 0;", and this will pause the application till you press the ENTER button.




//Feelay
Edited by Feelay (see edit history)

Share this post


Link to post
Share on other sites

Jep jep, I've always used this method to pause my C-applications :) . It's much better than system.pause() because cin.get() works for linux too (system.pause() is a windows-only app).

Share this post


Link to post
Share on other sites

Yes, I did this too to pause a console application, sometimes I did system("PAUSE"); too but it works if there is a command PAUSE, it is by default on Windows, I think it's not by default on Linux, but as I know anyone can create such a command on Linux too.. The bigger issue is with CLEAR and CLS due to they both are different on Linux and Windows, so you have to check someway what system your using and only when use to clear the terminal or command prompt by CLS or/and CLEAR ;]

Share this post


Link to post
Share on other sites

sorry, but what do you mean by if (getch() == 13)13 = the number for the enter key? if yes, can you please tell me where I can get the number for all keys, and if no, can you then please tell me what that is :)

Edited by Feelay (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.