• Advertisement
Sign in to follow this  

Which Complier?

This topic is 3458 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
Quote:
Original post by EasilyConfused
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.)


Ha! most beginners probably don't know what a batch file is!

@Moonshoe: Wow, I had no idea system("pause") was so huge and ugly. So much effort for so small a line...

Share this post


Link to post
Share on other sites
If you're not debugging and using breakpoints, why not just RUN your app from an open console window?

Share this post


Link to post
Share on other sites
sorry but
Quote:
3. open an operating system shell (relaunches the O/S in a sub-process)
Is the funniest thing I have heard this week. Use system pause if you want just know that it is non portable(which you may or may not care about) and there are other ways that are just as easy.

Share this post


Link to post
Share on other sites
I don't know how easy this is to do with VS 2008 C++ projects, but in C# projects you can set the program type to a Windows Forms type and the output will be sent to the VS console instead of the standard console. I find this to be more practical than using artifical pauses (like sleep or input) since I don't end up writing code that I'll have to delete later. Though ctrl+F5 seems like the best solution.

Share this post


Link to post
Share on other sites
Quote:
Original post by stonemetal
sorry but
Quote:
3. open an operating system shell (relaunches the O/S in a sub-process)
Is the funniest thing I have heard this week. Use system pause if you want just know that it is non portable(which you may or may not care about) and there are other ways that are just as easy.


Yeah...well, I think it was an extremely poorly-worded attempt at saying "OS launches a new process, switches to its context." Otherwise you're entirely correct, seeing as no sane person cares about its relative inefficiency in this case. Of course it's well worth understanding how an OS works, but this is utterly insignificant. system(anything) is pure evil in production code, as it's non-portable and can lead to security holes, but as a development/debugging aid, why not.

Share this post


Link to post
Share on other sites
There's also the factor that system("PAUSE") simply runs a program called 'pause' - like, pause.exe or something - with absolutely no guarantees as to what that would do. If I wanted to break your program very badly, I could make a copy of FORMAT.COM and drop it in your program's directory renamed to PAUSE.COM...

Share this post


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

  • Advertisement