Program is shutting down right after program is executed

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Program is shutting down right after program is executed

 
0
  #1
May 30th, 2003
I've made some C++ dos programs, and it runs fine, and does everything I want it to, but the moment it does the last line of code, it exits. I use Visual C++, and it stays on when I preview it in there, but after I compile it, and run it in the directory it was stored in, it exits right away after it's done.

Is there anyway to solve this? I've tried "System: Pause", but I think i'm doing it wrong.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Solved Threads: 1
Team Colleague
Bob Bob is offline Offline
Team Member
 
0
  #2
May 30th, 2003
Try adding the following line just before you return from main():

cin.get();

for example, a hello world program:

#include <iostream>
using namespace std;

int main()
{
cout << "Hello, world" << endl;
cin.get();
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 44
Reputation: MuddBuddha is an unknown quantity at this point 
Solved Threads: 0
MuddBuddha MuddBuddha is offline Offline
Light Poster

Reply

 
0
  #3
May 30th, 2003
If the "cin" doesn't work for you - try

system("PAUSE");
return 0;
}

This may not help whatsoever - I use Dev C++ and this is how it is done.

Hope it helps.....

The MuddBuddha ->
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Solved Threads: 1
Team Colleague
Bob Bob is offline Offline
Team Member
 
0
  #4
May 31st, 2003
"cin" is standard C++. If you have a C++ compiler it will work.

system("pause");

is a platform specific call. It's generally preferable to use portable solutions rather than platform specific where such a portable solution exists.
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 44
Reputation: MuddBuddha is an unknown quantity at this point 
Solved Threads: 0
MuddBuddha MuddBuddha is offline Offline
Light Poster

Reply

 
0
  #5
May 31st, 2003
Good point - Bob.....
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Program is shutting down right after program is executed

 
0
  #6
Jul 9th, 2003
Err...I'm a beginner in this. I'm not sure if adding a getchar() before your program ends would help or not.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,035
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 127
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Program is shutting down right after program is executed

 
0
  #7
Jul 9th, 2003
Mr Gates, were any of these suggestions helpful? I take it you got it working? A simple user input at the end of the program should offset it automatically exiting.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Re: Program is shutting down right after program is executed

 
0
  #8
Jul 10th, 2003
Yes, they seem to work great. I'm sorry I didn't reply earlier. :x
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,035
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 127
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Program is shutting down right after program is executed

 
0
  #9
Jul 10th, 2003
no problem
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC