11 Replies - 38161 Views - Last Post: 24 January 2006 - 10:56 AM Rate Topic: -----

#1 Introbulus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-January 06

Pause Application Execution

Posted 19 January 2006 - 08:27 PM

As you might imagine, I'm an expert C++ programmer. By which I mean, I have just started programming in C++ and have only an extremely vague idea as to what I'm doing. Nevertheless, I managed to build myself a program that actually compiled like it's supposed to. Now, for my class assignment, I have to analyze and explain the data.

Thing is...after I run the program, the data displays on screen for only a split-second before disappearing.

I remember my teacher for C programming showed me something once for Borlan that fixed this problem, the command "getch". Is there anything like this for C++ that'll let me pause the output so I can see what I'm getting?

Is This A Good Question/Topic? 0
  • +

Replies To: Pause Application Execution

#2 bluesuus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 26-December 05

Re: Pause Application Execution

Posted 19 January 2006 - 08:50 PM

yes ther is jus use the cin command before the end of ur program

or use the system pause command
system("PAUSE")

yhoughg i hv never used it
Was This Post Helpful? 0
  • +
  • -

#3 Introbulus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-January 06

Re: Pause Application Execution

Posted 19 January 2006 - 08:55 PM

Is the syntax for that just "cin" after the rest of my programming?
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Pause Application Execution

Posted 19 January 2006 - 09:35 PM

getch() is available in C++, but like the system("PAUSE") command, it is platform dependant, meaning that it does not comply to ANSI standards, and the code would not be portable. You can hold the program for user input be declaring a hold character, such as
char hold;


and then prompting the user for that character before returning a value to your main function:
cin.get(hold);
return 0;


Of course, one should really properly free the memory as well, but I have not shown that here.

Alternately, you can use the getchar() function, although it is really more of a c command.
Was This Post Helpful? 0
  • +
  • -

#5 Introbulus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-January 06

Re: Pause Application Execution

Posted 19 January 2006 - 09:42 PM

Wow...That works perfectly! ^^ Thank you very much! This is a great help to my project. ^^ Many many thanks.
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Pause Application Execution

Posted 19 January 2006 - 09:46 PM

No problem, friend...have a good evening.
Was This Post Helpful? 0
  • +
  • -

#7 Mrafcho001  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 41
  • View blog
  • Posts: 769
  • Joined: 01-November 05

Re: Pause Application Execution

Posted 20 January 2006 - 02:20 PM

You know if you want your application to stop for a few seconds and continue on its own without waiting for the user to push any buttons you could use the sleep API in the windows.h header file

Sleep(5000);



is how you use it, the number you pass to it is the number of milliseconds.
Was This Post Helpful? 0
  • +
  • -

#8 Jessehk  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 24
  • Joined: 06-January 06

Re: Pause Application Execution

Posted 21 January 2006 - 09:43 AM

Mrafcho001, on 20 Jan, 2006 - 03:17 PM, said:

You know if you want your application to stop for a few seconds and continue on its own without waiting for the user to push any buttons you could use the sleep API in the windows.h header file

Sleep(5000);



is how you use it, the number you pass to it is the number of milliseconds.

Yes, but once again, that is platform-specific code, which should be frowned upon.

Quote

As you might imagine, I'm an expert C++ programmer. By which I mean, I have just started programming in C++ and have only an extremely vague idea as to what I'm doing.


I found this to be quite funny. Thanks for the laugh. :)
Was This Post Helpful? 0
  • +
  • -

#9 eLliDKraM  Icon User is offline

  • Pepè Le Pewn
  • member icon

Reputation: 6
  • View blog
  • Posts: 6,565
  • Joined: 13-August 05

Re: Pause Application Execution

Posted 21 January 2006 - 06:39 PM

I just thought it necessary to share the pause key does not work :crazy:
Was This Post Helpful? 0
  • +
  • -

#10 Voodoo Doll  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 108
  • Joined: 24-January 06

Re: Pause Application Execution

Posted 24 January 2006 - 09:31 AM

>You can hold the program for user input be declaring a hold character
There's no need to declare a character, cin.get() will return the next character in the stream and you can just ignore it. Also, that method is all well and good if there's not already input in the stream. If there is, that call will appear to be skipped because it's immediately satisfied. This works in more cases:
#include <istream>
#include <limits>
#include <ios>

void flushis(std::istream& in)
{
  in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  in.get();
}


Since it's hidden in a function, you can forget about that scary ignore line and just say flushis(std::cin). :) But for those that are interested, it's akin to a loop that reads everything from the stream until a newline character, just flashier and more C++ish:
#include <istream>

void flushis(std::istream& in)
{
  char discard;

  while (in.get(discard) && discard != '\n')
   ;

  in.get();
}


You can take the function further with extra tests and templates to make it more broadly useful in error, locale, and extension situations, but when I try to explain that stuff I end up confusing myself as well as everyone else. :blink:
Was This Post Helpful? 0
  • +
  • -

#11 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Pause Application Execution

Posted 24 January 2006 - 09:55 AM

Excellent post...I agree that there is no need for actual character...I use it in demonstrations to make it more evident what is going on...sometimes new users are not familair with working solely with streams.

Welcome to dream in code! :)
Was This Post Helpful? 0
  • +
  • -

#12 Voodoo Doll  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 108
  • Joined: 24-January 06

Re: Pause Application Execution

Posted 24 January 2006 - 10:56 AM

Quote

sometimes new users are not familair with working solely with streams

I'm familiar with working with streams, even implementing them, and I still don't get it sometimes. :blink:

>Welcome to dream in code! :)
Thanks! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1