Jump to content
  • Advertisement
Sign in to follow this  
Helgunn

Auto close?

This topic is 4747 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

#include <iostream> int main () { std::cout << "Enter two numbers:" << std::endl; int v1, v2; std::cin >> v1 >> v2; std::cout << "The sum of " << v1 << " and " << v2 << " and " << v1 + v2 << std::endl; return 0; } This is what the C++ Primer 4th edition told me to make but... when I type in "3 7" and press enter, it shows my answer but disappears immediatly. Users in the chat have told me code to keep it up but I couldn't get (one) them to work and I don't want to do anything unless the book says it (for now). The users also said it has something to do with my settings in Dev-C++, does anyone know how to change it? Also, should I use Dev-C++ or some other program?

Share this post


Link to post
Share on other sites
Advertisement
The compiler creates an executable file from your source code. Find that file, open a console window and change the directory to the directory that the executable is created. Then run the program from the console window. So if your executable is in C:\mydirectory, use cd\mydirectory to change to that directory and run it from there.

Share this post


Link to post
Share on other sites
Quote:
Original post by dudedbz1
Yeah. But if you have no idea how to run from the command line just have cin.get() right before your return 0 in main().


I don't... :/ Why wouldn't the book tell me to include cin.get() ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Helgunn
I don't... :/ Why wouldn't the book tell me to include cin.get() ?


Well, the program will wait around anyway if you run it normally, it's closing when you run it from your IDE. In that sense, the extra cin.get() isn't really needed.

It won't hurt you to add it in so that you can easily see your program running without having to find it with the command prompt though, the important thing is that you learn from and understand the rest of the code the book presents.

Oh, and Dev-C++ is fine, plenty of people use it. If you aren't happy with it, you could also try Code::Blocks, which is also free, but either is perfectly fine, so there's no need for you to change unless you want to.

Share this post


Link to post
Share on other sites
The book DOES tell you. But instead of an easy cin.get() function it tells you to do cin.ignore(cin.rdbuf()->in_avail() + 1) in one of its tips.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!