Cant execute a c++ program

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2004
Posts: 2
Reputation: Calum is an unknown quantity at this point 
Solved Threads: 0
Calum Calum is offline Offline
Newbie Poster

Can't stop a program window from closeing after it has executed

 
0
  #1
Oct 27th, 2004
i'm using Dev C++, and when i write a program, it compiles it fine then when i execute it the program window closes after the program has finished.
does anyone know how to keep the window open. im running on XP(SP2).
i've tried right clicking on the .exe but theres nothing there to stop it closing.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Cant execute a c++ program

 
0
  #2
Oct 27th, 2004
You can open up a command line prompt and run the program that way, but the more common solution is to ask for input at the end of the program so that a blocking read pauses execution:
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. // Your program here
  8.  
  9. cin.get(); // Blocking read to pause
  10. }
This generally works unless there's still data left in the input stream, in which case your problem becomes one of flushing the input stream.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 11
Reputation: mr_mooz is an unknown quantity at this point 
Solved Threads: 0
mr_mooz mr_mooz is offline Offline
Newbie Poster

Re: Cant execute a c++ program

 
0
  #3
Oct 27th, 2004
You can add the following line at the end of you code to see a "press any key to conitinue....." type prompt to the user:

system("pause");


Your program is probably compiled fine its just not staying up after it has executed. U could always run it from the command prompt box.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Cant execute a c++ program

 
0
  #4
Oct 27th, 2004
>system("pause");
There must be some "God of the Newbies" who encourages stupid things like this. It's unsafe, nonportable, and slow. Can we say "triple threat"?
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 2
Reputation: Calum is an unknown quantity at this point 
Solved Threads: 0
Calum Calum is offline Offline
Newbie Poster

Re: Cant execute a c++ program

 
0
  #5
Oct 28th, 2004
Thanks alot :lol:

I'm sure ill be back
Reply With Quote Quick reply to this message  
Reply

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




Views: 3489 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC