When I click on the exe file to open it up via a folder or my desktop etc... it will show a black cmd window for about half a second and then close, however if i find the directory of my exe through cmd and then run it that way, it opens and operates successfully...

I compile using Digital Mars 847 (I believe)

I also run Windows XP

If you need any more info let me know, also I'm new to C++ so go easy on the jargon :D

Recommended Answers

All 7 Replies

When your program ends, windows automaticly closes the consolewindow. If you run it in CMD the window stays open because you opened it manually. Just add a getchar(); or a cin.get() to your code (the line before return 0; ) and the window should stay open.

Another one for a guaranteed result;

system("pause");

Another one for a guaranteed result;

system("pause");

That's true, the OP mentioned that he uses WinXP, but why would you use this non-portable way, if the other two solutions will also do the trick ?

Another one for a guaranteed result;

system("pause");

That is not guaranteed for the reason neik_e mentions. And it's a very BAD solution! See this

your exe is automatically stored in ur working folder after running the program ..... double click it and it shuld run.

Well, it is "guaranteed" since mark192 says he is using windows XP and not necessarily looking for portability.

On the other hand, neik_e mentions portability problems which is true (+using a system cmd is costly) However, with careless use of i/o functions (buffer problems), mostly because of the mistakes that inexperienced programmers make, program might not halt. This does not happen with system "pause". This is the second reason why it is guaranteed.

So, how bad it is, it might become handy all of a sudden.

Well, it is "guaranteed" since mark192 says he is using windows XP and not necessarily looking for portability.

On the other hand, neik_e mentions portability problems which is true (+using a system cmd is costly) However, with careless use of i/o functions (buffer problems), mostly because of the mistakes that inexperienced programmers make, program might not halt. This does not happen with system "pause". This is the second reason why it is guaranteed.

So, how bad it is, it might become handy all of a sudden.

Try reading the link I gave and quit spouting crap...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.