Why Does my Program disappear instantly when debugged?

I am a beginner, writing in a win32 console application...

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 7610 Views - Last Post: 10 July 2008 - 10:43 PM Rate Topic: -----

#1 xAlanxEnglandx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 06-July 08

Why Does my Program disappear instantly when debugged?

Posted 08 July 2008 - 11:24 PM

Hey people, I am a beginner, learning tutorials from a book called "a beginners guide to c++", I'me following this tutorial well, and learning all the principals...

But in the visual C++ express edition compiler, I had to run my program
as "Start without debugging", instead of "Start Debugging"

Woulden't "Start Debugging" be the best way to start the program, but when I do, it appears then disappears under a second... However when I run "Start Without Debugging" it stays around... Is there something the tutotial book isin't teaching me?

I've also seen in peoples code the term "endl" is this something to do with
holding the program around when debugged? I heard endl is similar to "\n"
but I'me not sure (The book teaches me "\n" but not "endl", is it even that
important

Thanks for any help back people and any help on making a program
stick around would be appeaciated (when debugged, assuming its the right way to run the program...)

Thanks!

This post has been edited by xAlanxEnglandx: 08 July 2008 - 11:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Why Does my Program disappear instantly when debugged?

#2 AmitTheInfinity   User is offline

  • C Surfing ∞
  • member icon

Reputation: 119
  • View blog
  • Posts: 1,565
  • Joined: 25-January 07

Re: Why Does my Program disappear instantly when debugged?

Posted 08 July 2008 - 11:43 PM

Well, endl is similar to '\n' it takes the console output to next line.

Now about your debugging problem. I think your program may not be disappearing, it is just going to your IDE to show you which line you are debugging. As you are debugging the code you are supposed press keys [step in, step over, run etc.] to continue with code run in debug mode. If code runs fine without debug on then it should run while debugging too. Just see if the window [console or frame, whatever] has got minimized or it went behind your IDE. If still your problem is not solved then put your code here and we will see the problem if any.

I hope this will help you. :)
Was This Post Helpful? 0
  • +
  • -

#3 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1431
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: Why Does my Program disappear instantly when debugged?

Posted 09 July 2008 - 04:40 AM

You might just not be holding the execution window open :)
Was This Post Helpful? 0
  • +
  • -

#4 Mallstrop   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 50
  • Joined: 19-June 08

Re: Why Does my Program disappear instantly when debugged?

Posted 09 July 2008 - 04:42 AM

There's a quick at --> http://www.dreaminco...wtopic30581.htm about holding the execution window open once the program has finished running.
#
Too slow, Gabehabe got there before me :(

This post has been edited by Mallstrop: 09 July 2008 - 04:43 AM

Was This Post Helpful? 0
  • +
  • -

#5 lanec42   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 229
  • Joined: 26-March 08

Re: Why Does my Program disappear instantly when debugged?

Posted 09 July 2008 - 03:38 PM

Try running your program from the command line.

Also...
I am also a n00b to C++, and I use both \n and endl. Endl is easier to see when looking at a program and trying to imagine how everything will display, but in some cases, \n is easier to code.
Was This Post Helpful? 0
  • +
  • -

#6 Tom9729   User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: Why Does my Program disappear instantly when debugged?

Posted 09 July 2008 - 06:46 PM

I am not a C++ programmer but you should probably get into the habit of using "\n" over "endl" because "\n" works in most other languages whereas "endl" I believe does not. :)
Was This Post Helpful? 0
  • +
  • -

#7 xAlanxEnglandx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 06-July 08

Re: Why Does my Program disappear instantly when debugged?

Posted 09 July 2008 - 10:44 PM

Hey guys, thanks I done the holding the execution window and quite happy using
system("pause");
It keeps the window in place for me when I run my program :)

Thanks everyone :)

This post has been edited by xAlanxEnglandx: 09 July 2008 - 10:48 PM

Was This Post Helpful? 0
  • +
  • -

#8 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1431
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 03:24 AM

I'd like suggest against using system("pause"); here, just like I always do whenever I see someone using it.

Anyway, it's much more efficient to use cin.get(); because it takes much less processing time, and can be used on any platform (whereas system makes a call to the OS, so it relies upon the OS having a pause command from the shell)
Was This Post Helpful? 0
  • +
  • -

#9 polymath   User is offline

  • D.I.C Addict
  • member icon

Reputation: 53
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 12:06 PM

And if you're going to use system("pause"); its much better to do system("pause>nul") because adding the >nul drops the message "Press any key to continue..._" so you can put your own message in there with cout.
Was This Post Helpful? 0
  • +
  • -

#10 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1431
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 12:11 PM

nooooooooo don't use system("pause"); :!:

OK, everyone follow this link

It explains it much better than I do.

Now it's time to post that link up in "holding the execution window open"
Was This Post Helpful? 0
  • +
  • -

#11 polymath   User is offline

  • D.I.C Addict
  • member icon

Reputation: 53
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 12:17 PM

system("pause") is fine if you aren't planning on distribution on non-windows platforms and you have a halfway-decent processor on your computer. For my computer, system calls can be executed with no difference that a human could possibly perceive than standard c/c++ functions. And it really isn't that fast, either.
Was This Post Helpful? 0
  • +
  • -

#12 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1431
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 12:28 PM

But the point is that cin.get(); is still more efficient!

So why use something that is less efficient than something else? -_-
Was This Post Helpful? 0
  • +
  • -

#13 polymath   User is offline

  • D.I.C Addict
  • member icon

Reputation: 53
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 12:30 PM

Well, what if you want the user to hit any key, not restricted to enter?
Was This Post Helpful? 0
  • +
  • -

#14 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1431
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 12:32 PM

Write your own function!
Was This Post Helpful? 0
  • +
  • -

#15 red_4900   User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Re: Why Does my Program disappear instantly when debugged?

Posted 10 July 2008 - 12:39 PM

Quote

So why use something that is less efficient than something else?


when you don't notice any difference.

although I myself would prefer using cin.get() than using system("pause").
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2