Jump to content
  • Advertisement
Sign in to follow this  
TwinDragons

Which Complier?

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

I have recently brought a book on c++ but the complier it recommended keeps skipping the rest of the code after i get some user input and closes the project. The software i am using is bloodshed Dev c++ version 4.9.9.2, i have also tried mircosofts c++ 2008 express edition but some of the coding in the book will not run with it. The question is what is the best IDE software to use? Thankyou in advance for answering my question!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by TwinDragons
I have recently brought a book on c++ but the complier it recommended keeps skipping the rest of the code after i get some user input and closes the project.

The software i am using is bloodshed Dev c++ version 4.9.9.2, i have also tried mircosofts c++ 2008 express edition but some of the coding in the book will not run with it.

The question is what is the best IDE software to use?

Thankyou in advance for answering my question!


Visual Studio 2008 Express.

If code from your book won't compile with it, the problem is almost certainly the book being out of date or some trivial UNICODE issues that are easily solvable, not the compiler. If the code is out of date, dump the book, not Visual Studio.

Regarding the project "closing" immediately after user input, this is probably a console project and it is actually normal behaviour for one to close after program termination.

Another great thing about Visual Studio is you can press Ctrl+F5 instead of run and Studio will execute a system PAUSE at the end of execution, allowing you to see the results of your program.

If you want to post some code from the book that won't compile with VS, I'm sure people will explain how to fix the code.

Share this post


Link to post
Share on other sites
What probably is happening is you aren't seeing your output.


#include <iostream>

using namespace std;

int main()
{
cout << "Hello World!" << endl;

// Right before termination insert a pause here
system("pause");
return 0;
}





This will allow you to see the output before the program quits.

Share this post


Link to post
Share on other sites
It's far more likely for your code to be at fault than the compiler or the book (not, by any chance, C++ For Dummies?). You might want to post the code for the offending program.

I keep hearing that you don't really want to use system("pause");. Just to check, does cin.getch() have the right functionality (returns after one key, regardless of whether it's an enter)?

Share this post


Link to post
Share on other sites
Whereas you probably shouldn't use system("pause") in real applications, I don't see why it would be so bad for a beginner to use while learning. You should rapidly move on to programs that run in some sort of loop, so keeping the console open in seldom a problem.

Keeping the program from terminating using only standard C++ input is technically a bit complicated for a beginner (if the program happens to accept any input). (And I don't know of a standard C++ input methods that would not require you to press Enter.)

Share this post


Link to post
Share on other sites
Quote:
Original post by theOcelot
Just to check, does cin.getch() have the right functionality (returns after one key, regardless of whether it's an enter)?


There's no cin.getch(). cin.get() sort of does what you want, but if there is input already sitting in the input buffer when it is called, it will not wait for a keypress so it won't do what you want.

As far as I am aware, since C++ has no concept of keyboard in the standard, just streams, there is no way using just standard C++ to reliably await a keypress.

However, although not standard, I've yet to find a compiler system that didn't support <conio.h> and getch() (or _getch() with VS to suppress some warnings) which actually specifically does what we want.

But for the problem of the vanishing console at program termination, in VS I just use Ctrl+F5 to run without debugging, which makes the enviornment rather than you program create the artificial pause.

Although I also agree with Visitor that for beginners, system("pause") is relatively harmless since few beginners seem to want to program from a command line anymore (where this problem is irrelevant).

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
Quote:
Original post by theOcelot
Just to check, does cin.getch() have the right functionality (returns after one key, regardless of whether it's an enter)?


There's no cin.getch(). cin.get() sort of does what you want, but if there is input already sitting in the input buffer when it is called, it will not wait for a keypress so it won't do what you want.

As far as I am aware, since C++ has no concept of keyboard in the standard, just streams, there is no way using just standard C++ to reliably await a keypress.

However, although not standard, I've yet to find a compiler system that didn't support <conio.h> and getch() (or _getch() with VS to suppress some warnings) which actually specifically does what we want.

But for the problem of the vanishing console at program termination, in VS I just use Ctrl+F5 to run without debugging, which makes the enviornment rather than you program create the artificial pause.

Although I also agree with Visitor that for beginners, system("pause") is relatively harmless since few beginners seem to want to program from a command line anymore (where this problem is irrelevant).


Crap, I was afraid of that! [lol]

Code::Blocks pretty much takes care of that, too. It has a separate program that runs your program, and that one displays information about yours before returning, and without even a special keyboard shortcut!

Share this post


Link to post
Share on other sites
Well, I'm glad about Code::Blocks. The thing is that if you put an artificial pause at the end of your program, then you happen to want to run the exe from a command line, the pause at the end suddenly becomes really annoying.

And putting your program inside a batch file becomes very difficult as well.

I'm well aware that very few beginners are ever going to do either of these things, which is why I consider system("pause") harmless at that level, but I guess it's good to be aware of the issues.

(Like, what happens if I put a pause.exe that reformats your harddrive in the same directory as your program for example. Woo ha ha ha.)

Share this post


Link to post
Share on other sites
I never really understood why system("pause") was so bad, either. But, I've read about it and this is why they say it's not a good habit. I've seen some people use getchar(), cin.get(), or even cin.ignore().get() as an alternative to system("pause").

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
Quote:
Original post by TwinDragons
I have recently brought a book on c++ but the complier it recommended keeps skipping the rest of the code after i get some user input and closes the project.

The software i am using is bloodshed Dev c++ version 4.9.9.2, i have also tried mircosofts c++ 2008 express edition but some of the coding in the book will not run with it.

The question is what is the best IDE software to use?

Thankyou in advance for answering my question!


Visual Studio 2008 Express.

If code from your book won't compile with it, the problem is almost certainly the book being out of date or some trivial UNICODE issues that are easily solvable, not the compiler. If the code is out of date, dump the book, not Visual Studio.

Regarding the project "closing" immediately after user input, this is probably a console project and it is actually normal behaviour for one to close after program termination.

Another great thing about Visual Studio is you can press Ctrl+F5 instead of run and Studio will execute a system PAUSE at the end of execution, allowing you to see the results of your program.

If you want to post some code from the book that won't compile with VS, I'm sure people will explain how to fix the code.

Yup! Another vote for VS2008 here!


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!