Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Pause A Command Prompt After Execution?
Feelay
post May 26 2008, 11:52 AM
Post #1


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



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.


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
CODE
cin >> name;


I added this:
CODE
cin.ignore();


Now this will allow me to add the:

CODE
cin.get();

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




//Feelay

This post has been edited by Feelay: May 27 2008, 07:56 PM
Go to the top of the page
 
+Quote Post
wutske
post May 29 2008, 09:37 AM
Post #2


Way Out Of Control - You need a life :)
Group Icon

Group: [HOSTED]
Posts: 1,048
Joined: 2-August 05
From: Kapellen (Antwerp, Belgium)
Member No.: 7,585



Jep jep, I've always used this method to pause my C-applications smile.gif . It's much better than system.pause() because cin.get() works for linux too (system.pause() is a windows-only app).
Go to the top of the page
 
+Quote Post
Quatrux
post May 29 2008, 07:57 PM
Post #3


the Q
Group Icon

Group: [HOSTED]
Posts: 1,054
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



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 ;]
Go to the top of the page
 
+Quote Post
magiccode9
post Jun 7 2008, 05:21 PM
Post #4


Member - Active Contributor
Group Icon

Group: [HOSTED]
Posts: 86
Joined: 7-November 05
Member No.: 9,489



Thank, that's help me a bit as I learning how to write c++.
While I do the same thing with getch() and check it's value if it is enter key then quit.

as this

CODE
if (getch() == 13)
{
    ...
}
Go to the top of the page
 
+Quote Post
Feelay
post Jun 10 2008, 12:47 PM
Post #5


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



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 tongue.gif

This post has been edited by Feelay: Jun 11 2008, 07:47 AM
Go to the top of the page
 
+Quote Post
magiccode9
post Jun 15 2008, 09:26 PM
Post #6


Member - Active Contributor
Group Icon

Group: [HOSTED]
Posts: 86
Joined: 7-November 05
Member No.: 9,489



Hi,

It is just the ASCII computer code and you can get it from here http://www.asciitable.com.
And yes, 13 is the key code for enter key. smile.gif


Regards,
Eric,
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Command Prompt Tips(1)
  2. Command Line (dos) Tips For Windows Xp(5)
  3. Linux Basic Command - For Storing Compilation Error To File(1)
  4. How To Boot To Command Prompt(12)
  5. Command And Conquer(7)
  6. Perl : Help(4)
  7. Easy Downloading Command For Linux (newbies)(2)
  8. How To Suspend / Resume Execution Of A Windows Application(4)
  9. Automatic/remote Php Script Execution(9)
  10. How To Open The Cmd Prompt When Blocked By Admins.(7)
  11. Xbox 360 'command & Conquer 3: Tiberium Wars' Keeps It Simple And Fun(2)
  12. Yahoo! Protocol: Part 18 - Arbitrary Code Execution(0)
  13. Command & Conquer 3!(8)
  14. phpBB avatar_path PHP Code Execution Vulnerability(3)
  15. "Command Prompt"(5)
  1. Britain Urged Against Saddam Execution(0)
  2. Winzip ActiveX Control Remote Code Execution Vulnerability(2)
  3. Command And Conquer(11)
  4. Microsoft Xmlhttp Activex Control Code Execution Vulnerability(0)
  5. Problem With Nested Latex Command Definition(0)
  6. Form Prompt(1)
  7. Yahoo! Protocol: Part 14 - Remote Code Execution?(0)
  8. Windows 2000 Prompt Authentication(0)
  9. Command Line Text Size(3)
  10. A Look At Yubnub(8)
  11. Make Elements Dynamic Without Defining Each(0)
  12. Auto Updating With One Command!(6)
  13. Microsoft Confirms Code Execution Hole In Ie(4)
  14. Command And Conquer(0)
  15. Microsoft Command Shell?(0)


 



- Lo-Fi Version Time is now: 13th October 2008 - 04:11 PM