CMD from excute closing instantly

Aug 13, 2014 at 6:14am
Hello, I compiled/built a code I had and made an executed file but when i click on it the CMD closes instantly. Is there anyway to keep this open?

Aug 13, 2014 at 9:22am
Aug 13, 2014 at 10:30am
I'll try to figure that out, thanks. A bit confusing right now but I'll play around with it.
Aug 13, 2014 at 1:57pm
add:
system("pause");

at the end of your codes.
example:
1
2
3
4
5
6
void main()
{
//your codes here blah blah
//...
system("pause");
}
Aug 13, 2014 at 2:07pm
@ tnavid: I've pretty much given up on discouraging the use of the "system()" function, but if you're going to suggest it then you HAVE to remind people to include the cstdlib header file. Also, main must return an integer. That's part of the standard.
Aug 13, 2014 at 2:42pm
why main must return integer? as you see it's "void main"
"main" function like other functions can be anytype: int,void,..
but you are right about stdlib header.
Aug 13, 2014 at 3:00pm
I know it's dryer then dust but, please, humor me for a minute: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf

The entry at the top of page 62 is what I was referring to.

An implementation shall not predefine the main function. This function shall not be overloaded. It shall
have a return type of type int,
but otherwise its type is implementation-defined.


Aug 13, 2014 at 3:04pm
Also here on the isocpp faq page ...

https://isocpp.org/wiki/faq/newbie#main-returns-int
Aug 14, 2014 at 1:55pm
I've read in a lot of places that using system("pause"); isn't the best thing to do. I mean I'll give it a try and see if I can get it working but a lot of people suggest other methods.

I appreciate the replies though. I'll mess around with it. It's still not working. :p
Aug 14, 2014 at 2:32pm
LOL. I'm almost past caring on this issue.
Aug 14, 2014 at 3:14pm
Figured it out, thanks everyone.
Topic archived. No new replies allowed.