command prompt trouble

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

command prompt trouble

Post 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.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

try adding a line

Code: Select all

system("pause");
at the end of main.
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post by James M. »

I solved it with getchar(), thanks guys. Didnt have to do that on my older computer running xp though.
Post Reply