Page 1 of 1

command prompt trouble

Posted: Thu Nov 11, 2004 3:33 am
by James M.
I was just gettiing back into c/c++ and I ran into a little wall. Every basic program I make cant stay open once he code is executed. I have a feeling this isnt code realated and jsut has to do with the fact that I am on xp running a "hello world" program. anyone know how to fix this or what I can do?

BTW, the only way i can check to see if whatever program I made worked right is if i open up the exe through command prompt.

Posted: Thu Nov 11, 2004 6:20 am
by kettle_drum
The command window that the code runs in shuts when the program finishes running....so you need to stop it from finishing until you say so....e.g. require some input from the user. So add <<cin or getchar() or the equivilent.

Posted: Thu Nov 11, 2004 7:02 am
by timvw
try adding a line

Code: Select all

system("pause");
at the end of main.

Posted: Thu Nov 11, 2004 2:22 pm
by James M.
I solved it with getchar(), thanks guys. Didnt have to do that on my older computer running xp though.