Thursday, July 30, 2009

Having difficulties with c++ compiler??

so like i type correctly all the codes and like the compiler wont show me any errors, and like when i finish the typing and i compile it and it shows me that it compiled it successfully . but when i press on the program it wont show me the results. this black window just opens for a second and it closes and doesnt show me what it was supposed to. and now i am talking about real simple orders like to appear me a phrase or sth, nothing more, and it doesnt.


my compiler is bloodshed Dev-C++ 4.9.9.2

Having difficulties with c++ compiler??
It looks like your program runs (apparently in a console session), completes, and exit - then the console session goes away. You could do a couple of things: start a console session and execute your program from there, or add a single input statement at the end of your program to keep the console session open.
Reply:you should give getch() function before closing the main function then you can see the answer ,,,, I think like that you met ,,





ok





fine
Reply:That is the way Windows works with console applications... As it was mentioned, your program starts, runs, prints its results, completes and ... Windows close the completed application window at the same moment, not waiting for you to look at the result!





There are several different ways to get over this problem. The simplest, imho, is to add some code to the end of your program, that will make it work until you instruct it to quit.


For example, you may add the following instruction to your application:





getch();





It will just wait for you to press any key. You can make it even nicier:





puts("Press any key to quit..."); getch();





NB: to use "getch()" you may need to include an appropriate header file. I.e. add the following line to other includes:





#include %26lt;conio.h%26gt;


No comments:

Post a Comment