User forums > Using Code::Blocks

Application not running

(1/2) > >>

kaulimus:
Hello, all!

I have a newbie question for you. I'm just learning to program with C++ (or rather, reviewing some of what I already knew to get to the stuff I don't). I've written and built my "Hello World" application no problem. It runs from the compiler just fine. When I double click my application's icon on the desktop, however, nothing happens. Is this normal?

Thanks,
-Jake

thomas:
No. If this were normal, you would need Visual Studio to run Microsoft Word.

Probably "nothing happens" is not correct, either. More likely it only happens too fast for you to see.
Try running cmd and starting your Hello World from there.

kaulimus:
I'll give it a shot and do some more fiddling around.

And yes, you're accurate in saying that "nothing happens" is not the best way to phrase what is happening. It happens just fast enough for me to catch a glimpse of the application before it terminates.

EDIT: I can get it to run in the command prompt window. Any ideas as to why it won't otherwise?

Thanks,
-Jake

eckard_klotz:
Hello Jake.

I think this is the normal behaviour under windows if you don't have an input-command or a command like system("PAUSE") at the end of the application. I guess your application has only an output-command to print the "Hello World" to the screen.  After that the program is finished, right?

And that's what windows is doing. A terminal-window is opened, "hello world" is printed and the terminal-window is closed because there is no need to let it open for nothing. You can solve this problem in several ways.

1. You can write a batch-file to run your application with the command PAUSE at the end without changing your application. This gives the user the chance to decide if the window should close or not after the program is finished. If your application should be combined with other applications it may be useful if there is no need to close the window by hand to step further except for batch-file debugging.

2. You can ad the command system("PAUSE"); after the output-line of your c-source but this is not supported of all operation systems and it is officially not recommended.

3. You can add a loop with a real input-command after the output-line. Run the loop until the user inputs "exit" or something like this.

I hope this will help you,

                                  Eckard.

JGM:

--- Quote from: eckard_klotz on December 12, 2007, 05:47:06 am ---2. You can ad the command system("PAUSE"); after the output-line of your c-source but this is not supported of all operation systems and it is officially not recommended.

--- End quote ---

the function getchar() on the stdio.h or cstdio is also a good alternative at the end of the program, really simple one.

Navigation

[0] Message Index

[#] Next page

Go to full version