User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,798 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,350 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 3939 | Replies: 8
Reply
Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Program is shutting down right after program is executed

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Colleague
Bob Bob is offline Offline
Team Member
  #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  
Join Date: May 2003
Posts: 44
Reputation: MuddBuddha is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
MuddBuddha MuddBuddha is offline Offline
Light Poster

Reply

  #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  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Colleague
Bob Bob is offline Offline
Team Member
  #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  
Join Date: May 2003
Posts: 44
Reputation: MuddBuddha is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
MuddBuddha MuddBuddha is offline Offline
Light Poster

Reply

  #5  
May 31st, 2003
Good point - Bob.....
Reply With Quote  
Join Date: Jun 2003
Location: Malaysia
Posts: 313
Reputation: red_evolve is on a distinguished road 
Rep Power: 6
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

  #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  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,881
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 108
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Program is shutting down right after program is executed

  #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.
Reply With Quote  
Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Re: Program is shutting down right after program is executed

  #8  
Jul 10th, 2003
Yes, they seem to work great. I'm sorry I didn't reply earlier. :x
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,881
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 108
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Program is shutting down right after program is executed

  #9  
Jul 10th, 2003
no problem
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC