Jump to content
  • Advertisement
Sign in to follow this  
The Little Guy

Dev C++ Program help

This topic is 5126 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I am staring my first program, that "Hello World!" thing, any ways I am using Dev C++ 4 from bloodshed, and when ever I compile and run my program it shows no errors, but the window that pops up and then dissapears. It is up for less than a second. Is there a way to fix that?

Share this post


Link to post
Share on other sites
Advertisement
Right before your 'return' line put in
system("pause");
That will run your program and then wait for a key press before exiting.

Share this post


Link to post
Share on other sites
Quote:
Original post by The Little Guy
Ok I am staring my first program, that "Hello World!" thing, any ways I am using Dev C++ 4 from bloodshed, and when ever I compile and run my program it shows no errors, but the window that pops up and then dissapears. It is up for less than a second. Is there a way to fix that?


you just need to add a pause to your program so it stays open after the message is displayed. You can do this by including cstdlib and adding system("PAUSE"); before the return statement.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by The Little Guy
I added that and now I get 1 error.

Here is what I have


#include <iostream>

int main()
{
std::cout << "Hello World!\n";
system("pause");
return 0;
}


You need to include cstdlib
Try the following code:


#include <iostream>
#include <cstdlib>

int main()
{
std::cout << "Hello World!\n";
system("pause");
return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by The Little Guy
Thanks, The book that I'm using told me to take that part out of the equation. (Sams Teach Yourself C++ In 24 Hours)


You're welcome. I think it depends on the compiler. In my experiance MinGW tends to be pretty strict about it. In my opinion it best to just to include it. I don't think you save anything by leaving it out. :)

Share this post


Link to post
Share on other sites
you only need to add the system("PAUSE"); if you're running your program from the IDE. if you go to the directory in windows and open it, or if you run it from the command line, it won't matter if you have the system("PAUSE");.

Share this post


Link to post
Share on other sites
WHy are you running Dev-C++ 4? Go get Dev-C++ 5. It is a lot more current and should be of more help. And one of the best Dev-C++ references is the mailing list, sign upm at bloodshed.net.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!