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 423,534 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 4,369 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: Programming Forums
Views: 1219 | Replies: 12
Reply
Join Date: Nov 2007
Location: Singapore
Posts: 25
Reputation: kartik14 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kartik14's Avatar
kartik14 kartik14 is offline Offline
Light Poster

Help Output window disappears instantly !!!!

  #1  
Feb 2nd, 2008
When I compile and run my programs in Dev C++, the output window opens and shows the output. Then instanlty the window flashes and disappears.

How do I make the window stay long enough for me to read the output??

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: Ireland
Posts: 1,745
Reputation: twomers will become famous soon enough twomers will become famous soon enough 
Rep Power: 6
Solved Threads: 32
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso

Re: Output window disappears instantly !!!!

  #2  
Feb 2nd, 2008
The problem is (not really a problem), that the program is running too fast and doesn't have anything to stop it from closing. There are a number of options to solve this, most of them are mentioned here -- http://faq.cprogramming.com/cgi-bin/...&id=1043284385 so if you're using C++ throw a cin.ignore(); and cin.get(); before you return 0; at the end of your program
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote  
Join Date: Jan 2008
Posts: 55
Reputation: carnage is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
carnage carnage is offline Offline
Junior Poster in Training

Re: Output window disappears instantly !!!!

  #3  
Feb 2nd, 2008
here at home i'm using dev c++ and i do get the same "problem"

i use system("pause") which i think is not preferred by others,but it's just me using it to see the output
then i just remove it when i'm at school because there we use visual c++

OR

run the program with the command prompt
Last edited by carnage : Feb 2nd, 2008 at 8:00 am.
Reply With Quote  
Join Date: Dec 2007
Posts: 157
Reputation: atish00 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
atish00 atish00 is offline Offline
Junior Poster

Re: Output window disappears instantly !!!!

  #4  
Feb 2nd, 2008
use getch in the end....
though getch is used to input.

cout<<"c++ is cool"<<endl;
getch(); // freezez the screen till a key is pressed.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Output window disappears instantly !!!!

  #5  
Feb 2nd, 2008
Don't use
  • getch()
  • system("PAUSE")

Both are non-portable.

Instead, do it the C++ way:
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. void pause() {
  5. std::cout << "Press ENTER to continue... ";
  6. std::cin.ignore( std::numeric_limits<streamsize>::max(), '\n' );
  7. }

Now if you want to pause, just use the function:
  1. int main() {
  2. using namespace std;
  3. string name, color;
  4.  
  5. cout << "WHAT, is your NAME!?\n";
  6. getline( cin, name );
  7.  
  8. cout << "WHAT, is your favorite COLOR!?\n";
  9. getline( cin, color );
  10.  
  11. cout << "Aaaiiiiiieeeee!\n";
  12.  
  13. pause();
  14. }

Hope this helps.
Last edited by Duoas : Feb 2nd, 2008 at 1:58 pm.
Reply With Quote  
Join Date: Dec 2007
Posts: 157
Reputation: atish00 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
atish00 atish00 is offline Offline
Junior Poster

Re: Output window disappears instantly !!!!

  #6  
Feb 2nd, 2008
what does non-portable mean ??

and what does pause(); do?
Reply With Quote  
Join Date: Dec 2007
Posts: 157
Reputation: atish00 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
atish00 atish00 is offline Offline
Junior Poster

Re: Output window disappears instantly !!!!

  #7  
Feb 2nd, 2008
what does non-portable mean ??

and what does pause(); do?
Reply With Quote  
Join Date: May 2007
Location: Ireland
Posts: 1,745
Reputation: twomers will become famous soon enough twomers will become famous soon enough 
Rep Power: 6
Solved Threads: 32
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso

Re: Output window disappears instantly !!!!

  #8  
Feb 2nd, 2008
Non portable means that the code won't work on all systems -- suppose you were to compile on one system it might work but that doesn't mean it will compile on all systems. Using system is a bad idea for pausing. getch() is a lazy excuse. Duoas' solution is good. Use that.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote  
Join Date: Dec 2007
Posts: 157
Reputation: atish00 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
atish00 atish00 is offline Offline
Junior Poster

Re: Output window disappears instantly !!!!

  #9  
Feb 2nd, 2008
Itz asking for a header file for pause and its giving a warning that function should return a value.
Reply With Quote  
Join Date: May 2007
Location: Ireland
Posts: 1,745
Reputation: twomers will become famous soon enough twomers will become famous soon enough 
Rep Power: 6
Solved Threads: 32
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso

Re: Output window disappears instantly !!!!

  #10  
Feb 2nd, 2008
No idea about pause, but the warning is solved by putting a return 0; before the closing } in main:

int main() {
  // Your code

  return 0;
}
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote  
Reply

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

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C++ Forum

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