Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Program closing too fast...
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
moridin




PostPosted: Tue Sep 18, 2007 5:43 pm   Post subject: Program closing too fast...

I'm just getting into programming in C++ and I'm using Bloodshed Dev C++ 4.9.8.0. When I compile and run code, all output to the monitor is only displayed for about 20 milliseconds and then closes, to have the output displayed longer I've been making the program wait for input from the keyboard before closing. I'm just wondering if there is some better way to keep the program open, instead of closing immediately after it runs. Perhaps some setting in the compiler that I can't find?
Sponsor
Sponsor
Sponsor
sponsor
StealthArcher




PostPosted: Tue Sep 18, 2007 6:04 pm   Post subject: Re: Program closing too fast...

Thats about it.

Most programs are looped,m and close aty a typed command.

(i just started this lang though, so i might be wrong....)
Tony




PostPosted: Tue Sep 18, 2007 6:14 pm   Post subject: Re: Program closing too fast...

StealthArcher @ Tue Sep 18, 2007 6:04 pm wrote:
(i just started this lang though, so i might be wrong....)

You are, but that's ok.

So here's the deal - when you run a program, it opens up a console for all of your output. When the program terminates, there is no longer any reason for the console to stick around, so it closes itself as well.

What you should be doing, is opening your console first (I think it's Start->run->cmd), and then running your compiled program from there. You would obviously have to navigate to the file's location first (cd path/to/file) and run it by typing in the file_name.exe.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




PostPosted: Tue Sep 18, 2007 10:04 pm   Post subject: RE:Program closing too fast...

You can also put in a line of code at the end of your program to wait for input (like 1 char) intill contuing so it will not terminate befor you read it all.

Somthing like:

printf("hit any key");
std::cin.get();


Note: you need to include iostream.h for cin.get i blive.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Cinjection




PostPosted: Tue Sep 25, 2007 5:36 pm   Post subject: Re: RE:Program closing too fast...

Dan @ Tue Sep 18, 2007 10:04 pm wrote:

Note: you need to include iostream.h for cin.get i blive.


Yup, you will have to #include <iostream>. Not <iostream.h> though.
md




PostPosted: Tue Sep 25, 2007 7:00 pm   Post subject: RE:Program closing too fast...

You shouldn't add anything to the end of your program to delay it. While it does work it's not the right thing to do.

Run it from a command line like it's supposed to be.
Dan




PostPosted: Tue Sep 25, 2007 7:06 pm   Post subject: Re: RE:Program closing too fast...

md @ 25th September 2007, 7:00 pm wrote:
You shouldn't add anything to the end of your program to delay it. While it does work it's not the right thing to do.


That realy depends on what it is sposted to do....

If your target is windows users or just your self (or your self and a marker) it could aucatly make things easyer.

If you are making a real console application then you are right.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: