Thursday, July 30, 2009

I'm trying to learn C++.?

I have down loaded Dev-C++ and try to program hello world and it compiled with no problem but when I run the program I don't see the out put. It prompts a window for a fractions of secods then it goes away. What can I do to fix this problem.

I'm trying to learn C++.?
I know what you're talking about. At the end of the program, before return 0; and the cloisng } add the line:





system("PAUSE");





The window closes the instant the program completes. This executes the MS-DOS command "PAUSE", which waits for you to press a key before returning.





So just add that line and recompile. That should do it!
Reply:Does it run in console window? Just start the program from console, and it won't close after the program has ended, instead you'll get the prompt back.
Reply:you have to write at the end


system("PAUSE");





then the program will stop with a message like : press any key to continue





and the console window wont close
Reply:Bloodshed Dev-C++ is sometimes a complex IDE because of its volatile nature.


You can try restarting the program and the computer, see if that helps, but it sounds like you're missing the System "PAUSE"; line before the Return line in the main function.


If you aren't using a returnable main, you're using a void main()... in that case just put a System "PAUSE"; at the bottom.


No comments:

Post a Comment