By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,136 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,136 IT Pros & Developers. It's quick & easy.

Dev C++ Problem

P: 15
Hi guys, im confused with my program, actually im using borland c++ before and it compiles, but when i change my compiler to dev c++, my program compiles but when i run the program and the first question appears on the screen and when i input the value it shuts down automatically, and it would'nt print the other output that comes out before when i using borland C++..

can anyone help me on this...

thanks in advance'
Dec 21 '06 #1
Share this Question
Share on Google+
1 Reply


100+
P: 145
Hi guys, im confused with my program, actually im using borland c++ before and it compiles, but when i change my compiler to dev c++, my program compiles but when i run the program and the first question appears on the screen and when i input the value it shuts down automatically, and it would'nt print the other output that comes out before when i using borland C++..

can anyone help me on this...

thanks in advance'
Borland sneaks in some code that pauses the program prior to exit. (It's a non-standard behavior.)

To explicitly get that behavior in Dev-C++, mingw, g++, etc, add the following to the end of your program:
Expand|Select|Wrap|Line Numbers
  1.  // .. remainder of your code in main()
  2.  
  3.  system("pause");
  4.  return 0;
  5. }
  6.  
An alternative (which doesn't depend upon the system's pause command):
Expand|Select|Wrap|Line Numbers
  1.  // ... remainder of your code in main()
  2.  
  3.  cout << "Press any key to exit ... " << endl;
  4.  char c = getchar();
  5.  return 0;
  6. }
  7.  
Note that you'll need to include <cstdio> for the second method. -- Paul
Dec 21 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.