How do I retain output window in Dev-C++

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

Join Date: Dec 2007
Posts: 5
Reputation: rwkopcke is an unknown quantity at this point 
Solved Threads: 0
rwkopcke rwkopcke is offline Offline
Newbie Poster

How do I retain output window in Dev-C++

 
0
  #1
Dec 20th, 2007
Dev-C++ v 4.9.9.2 IDE
When I compile and run my program as a console project, a window flashes very briefly on the screen and disappears. The compile log says compilation was successful and execution terminated.

How to I keep the window (my output window?) from disappearing?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How do I retain output window in Dev-C++

 
0
  #2
Dec 20th, 2007
You have to add a line just before the end of main() to stop the program from closing. Most people call getch() or c++ cin.get(), which is just waiting for keyboard entry.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 66
Reputation: superjacent is an unknown quantity at this point 
Solved Threads: 3
superjacent's Avatar
superjacent superjacent is offline Offline
Junior Poster in Training

Re: How do I retain output window in Dev-C++

 
0
  #3
Dec 20th, 2007
You may want to have a look here http://www.daniweb.com/forums/thread90228.html.

Here's a snippet you can include at the end of main(), just prior to the return statement.
  1. // exit routine
  2. cout << "\n\n...Press ENTER to Exit System...";
  3. cin.get();
or, if that doesn't work, pressing ENTER and nothing seems to happen, which is most likely due to the fact that cin refuses to accept any more characters due to it being in an error state and that error needs to be erased or cleared out; try this
  1. cout << "...Press ENTER to Exit System...";
  2. cin.clear();
  3. while (cin.get() != '\n')
  4. ;
  5. cin.get();
I'm still learning this stuff and most likely other more experienced forum members could better explain things. From my experience, reading up on cin and understanding why errors may occur (ie. assigning alphbetical characters to a numerical variable) will dictate what method you use.

And that's it, my first bit of advice, hope I'm on the mark.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: How do I retain output window in Dev-C++

 
0
  #4
Dec 20th, 2007
why should we not use system("pause");
Last edited by rajatC; Dec 20th, 2007 at 2:59 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 66
Reputation: superjacent is an unknown quantity at this point 
Solved Threads: 3
superjacent's Avatar
superjacent superjacent is offline Offline
Junior Poster in Training

Re: How do I retain output window in Dev-C++

 
0
  #5
Dec 20th, 2007
Originally Posted by rajatC View Post
why should we not use system("pause");
You are relying upon that program (pause.exe) being available and in that particular context it's only applicable or valid for Windows. I wrote a quick 'hello world' in Linux, it compiled ok, with system("pause") but on running it this is the output:
>./test
sh: pause: not found
Hello World
If you do away with system("pause") then you can easily transfer your code and compile under other operating systems without having to make any modifications.

I'll re-state, I'm still learning this stuff and more experienced members might explain it better.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: How do I retain output window in Dev-C++

 
0
  #6
Dec 20th, 2007
i dont know this is correct or not but is there anything like this..

that when we use system("pause"); then the system remains in the wait state and is not free for any other process...but if we use cin.get(); then the system will do other processes too and will keep on checking the input stream (for any input entered by the user) after each instruction cycle of it's process...
this way the system will be able to do other processes too...it is kind of simulating many processes efficiectly making use of system's time..

@experts..
plz check is it correct or i m wrong about it..
Life is about being happy...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How do I retain output window in Dev-C++

 
0
  #7
Dec 20th, 2007
Originally Posted by rajatC View Post
..@experts..
plz check is it correct or i m wrong about it..
You are wrong. system("pause"); does not pause the operating system, although I suppose someone could write an operating system in which it would pause it but it would be pretty stupid to do that.
Last edited by Ancient Dragon; Dec 20th, 2007 at 6:57 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 5
Reputation: rwkopcke is an unknown quantity at this point 
Solved Threads: 0
rwkopcke rwkopcke is offline Offline
Newbie Poster

Re: How do I retain output window in Dev-C++

 
0
  #8
Dec 20th, 2007
cin.get(); works fine for compile and run. But when I choose simply to run again, after having compiled and run. The output window only flashes briefly again.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,660
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: 723
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How do I retain output window in Dev-C++

 
0
  #9
Dec 20th, 2007
>You are relying upon that program (pause.exe) being available
You're also relying on that program doing what you expect it to do. The problem is that one can easily replace pause.exe with another program of the same name but a malicious payload. system("pause"); isn't portable, but the real kicker is that it's a huge security hole.

>But when I choose simply to run again, after having compiled
>and run. The output window only flashes briefly again.
That sounds like an order of operations thing, though it's hard to say without knowing what compiler you use. You may be running an old version of the program that didn't have a pause at the end. Always compile before you run the program to avoid this problem.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: How do I retain output window in Dev-C++

 
0
  #10
Dec 20th, 2007
Ok...thanks...
Life is about being happy...
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