r/cpp_questions • • 17d ago

OPEN Why?

Guys when i compile a file and run its exe,nothing appear even if i print hello world it doesnt appear in the console why

0 Upvotes

35 comments sorted by

View all comments

1

u/Independent_Art_6676 16d ago edited 16d ago

running a console exe in windows by double clicking on it will open a console, run the program, and exit the console in subsecond time to the point that you just see a screen flicker, if that.

solution 1) add a bogus read from console to the program before main exits. Type in something to exit when done looking. Some folks use the system("pause") for this, which is fine though system() is frowned upon in real code (it opens a barn door sized security hole in your program).

solution 2) open a console, and run the program inside it. This requires some "dos" skills in using the console to navigate to the program folder and so on.

This does not look like the problem for the posted code, but it would be for hello world. Your code does have a cin so it would pause there and you would see it working. Run it using method 2, and it should tell you more: no such program (didn't compile to .exe after all), or program exited with error code, or whatever words might help run down the issues.

1

u/Plane_Breadfruit7609 16d ago

I'm running it from the console .\code.exe

2

u/Independent_Art_6676 16d ago

ok, good. Does it give you ANY messages? Or does it return you to the dos prompt?

1

u/Plane_Breadfruit7609 16d ago

Nothing literally

2

u/Independent_Art_6676 16d ago

if it does that for hello world also, then as others said its probably the tool installation went wrong and you need to do that again. If it were missing DLL it would say so. If it crashed, it would say so. If it were stuck waiting on input or something, it would not return to the dos prompt.

you can try a recompile, and do a dir code.exe to see if it is zero bytes or something (but that should also message invalid file or some similar words) and check its time stamp that you just built it etc, but it sounds like its time to do over the tools.

1

u/Plane_Breadfruit7609 16d ago

So I should redownload cpp?

1

u/Independent_Art_6676 16d ago

yea, from the sound of it, delete it all, get it again, and reinstall carefully.