Which Complier?

Started by
14 comments, last by superpig 15 years, 8 months ago
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!
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.
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.
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)?
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.)
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).
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!
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.)
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").
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!


[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

This topic is closed to new replies.

Advertisement