Loans | Mobile Phones | Loans | Mortgages | Babb Fest
dev-C++, keep programs open [Archive] - PCMech Forums

PDA

View Full Version : dev-C++, keep programs open


ghost2003
04-27-2004, 04:10 PM
I want to learn c++ and since dev-c++ was recomended by a couple of web sites I downloaded it. The problem is that when I make console apps they close too fast. How do I keep them open after they finished executing the code?

doctorgonzo
04-27-2004, 04:13 PM
Put this line at the end of the main function code block (before the closing }):

system("PAUSE");

That will require you to hit a key before proceeding.

ghost2003
04-27-2004, 04:18 PM
now it gives me:

7 untitled1.cpp
implicit declaration of function `int system(...)'

doctorgonzo
04-27-2004, 04:20 PM
You will need to put the following include statement at the beginning then:

#include <stdlib.h>

As a pointer, if you go to File...New...Project, and then select "Console Application," it will do this automatically for you.

I should add that the system statement needs to go before any return statement, if there is one.

ghost2003
04-27-2004, 04:24 PM
Works now, thanks. But it puts #include < stdio.h > automaticly, not #include < stdlib.h >

ghost2003
04-30-2004, 06:19 PM
Dont wanna start a new thread just for this. How do I make stuff go on the next line? I made a program and its all in 3 lines when it should be in 10.

oh, devC++ is set to put

#include < iostream.h >
#include < stdlib.h >

int main()
{

system("PAUSE");
return 0;
}

when it make a new project but instead it puts


#include < stdio.h >

int main(int argc, char *argv[])
{

return 0;
}

doctorgonzo
04-30-2004, 07:06 PM
To add a carriage return, use endl:

cout<<"This is on one line"&lt;&lt;endl;
cout<<"This is on the next line"&lt;&lt;endl;

Edit: Fixed brackets.

ghost2003
04-30-2004, 07:18 PM
thanks again!