Sign in to follow this  
omgh4x0rz

my c++ program crashes

Recommended Posts

omgh4x0rz    122
It runs through all my code, and then instead of the black window sitting there with the "press any key to continue" message, it just instantly closes and I get this error. The program '[4100] tehprogram.exe: Native' has exited with code 0 (0x0). My temporary solution is just using a system("PAUSE") at the very end, which makes the black box stay there. However, I still get the error after I "press any key" and finish the program. I'm not sure what to do about it. Thanks

Share this post


Link to post
Share on other sites
njkt    145
looks more like the program you're using to launch the program is simply notifying you that the program executed and returned fine.

Share this post


Link to post
Share on other sites
KulSeran    3267
2 things.
1) Your program shouldn't end with a "press any key to continue"
Visual Studio(and other windows IDE's) only does this because otherwise you wouldnt see anything.
You should launch console apps from the console, not by doubleclicking the exe.
Unless you dont expect any text output.

2) Your program "exited with code 0" is telling you that your program hit a return
statement in main "return 0;", and thus exited normally.

Share this post


Link to post
Share on other sites
Crypter    748
Return code 0 useually indicates success, so your program is executing just
fine.

The "Black box" is the command prompt. After your program terminates,
the command prompt will terminate unless you add code to keep it open
(such as system ("pause"))

When you run the program within an IDE, the IDE useually appends the code,
so the command prompt stays open after the program terminates.

btw, "system" is system dependent, and is not recommended. A better method
is using cin.get(), ie:

cout << "Press any key to exit..." << endl;
char c = cin.get();
cin.get();


Hope this helps;

Share this post


Link to post
Share on other sites
omgh4x0rz    122
ok, but it hasn't been doing this before. I have been just compiling it and running it in visual studios since I'm still working on it, and it hasn't done this before. I can't recall changing anything recently... so why would it start doing this now? Plus, since it exits immidiatly, it wouldn't let me see any output. Why would this be normal?

thanks for the quick responses everyone. Thanks for the alternate code crypter, I didn't realize system was bad to use.

Share this post


Link to post
Share on other sites
Driv3MeFar    1080
Quote:
Original post by Crypter
btw, "system" is system dependent, and is not recommended. A better method
is using cin.get() to simply run your console applications from the console window.


Fixed. Artificially pausing your programs by any means is bad form. Other options in Visual Studio are to set a breakpoint at the return statement in main, and view the output in the console window before continuing, or run without debugging (ctrl+f5).

Share this post


Link to post
Share on other sites
KulSeran    3267
If it is crashing, run it in the debugger.
So instead of exiting, it will stall out on the error.
If it doesn't stop at the error, then add a breakpoint at the begining of
your program, and step through it till it crashes.

Share this post


Link to post
Share on other sites
njkt    145
Quote:
Original post by omgh4x0rz
ok, but it hasn't been doing this before. I have been just compiling it and running it in visual studios since I'm still working on it, and it hasn't done this before. I can't recall changing anything recently... so why would it start doing this now? Plus, since it exits immidiatly, it wouldn't let me see any output. Why would this be normal?


since i don't use visual studio i won't comment on that aspect but your program closing is normal because you haven't specifically forced it to stay open (ex: asking for input) you could, however, run it from the console and view the output without the console closing.

Share this post


Link to post
Share on other sites
Matt328    272
It sounds like you are working with a console application, meaning in its finished state, its meant to be run from a console window. If you open a command window, cd to the directory containing your executable and run it, you'll see your output in the command window.

Visual Studio is kinda nice in that it will fire up the program for you and tacks a pause statement at the end as a convenience during development. The release build is meant to be run from the command line.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this