Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-27-2004, 03:10 PM   #1
Lest we forget
 
ghost2003's Avatar
 
Join Date: Jun 2003
Location: Ontario, Canada
Posts: 1,870
dev-C++, keep programs open

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?
__________________
redqueen: Antec Sonata, Pentium-D 2.5GHz, MSI G31M3-L, 2GB ram, 320 GB HDD, OpenBSD
hal9000: Lenovo T61, 2GB ram, 120 GB HDD, FreeBSD
ghost2003 is offline   Reply With Quote
Old 04-27-2004, 03:13 PM   #2
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
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.
doctorgonzo is offline   Reply With Quote
Old 04-27-2004, 03:18 PM   #3
Lest we forget
 
ghost2003's Avatar
 
Join Date: Jun 2003
Location: Ontario, Canada
Posts: 1,870
now it gives me:

7 untitled1.cpp
implicit declaration of function `int system(...)'
ghost2003 is offline   Reply With Quote
Old 04-27-2004, 03:20 PM   #4
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
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.
doctorgonzo is offline   Reply With Quote
Old 04-27-2004, 03:24 PM   #5
Lest we forget
 
ghost2003's Avatar
 
Join Date: Jun 2003
Location: Ontario, Canada
Posts: 1,870
Works now, thanks. But it puts #include < stdio.h > automaticly, not #include < stdlib.h >
ghost2003 is offline   Reply With Quote
Old 04-30-2004, 05:19 PM   #6
Lest we forget
 
ghost2003's Avatar
 
Join Date: Jun 2003
Location: Ontario, Canada
Posts: 1,870
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;
}
ghost2003 is offline   Reply With Quote
Old 04-30-2004, 06:06 PM   #7
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
To add a carriage return, use endl:

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

Edit: Fixed brackets.

Last edited by doctorgonzo; 04-30-2004 at 06:28 PM.
doctorgonzo is offline   Reply With Quote
Old 04-30-2004, 06:18 PM   #8
Lest we forget
 
ghost2003's Avatar
 
Join Date: Jun 2003
Location: Ontario, Canada
Posts: 1,870
thanks again!
ghost2003 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:53 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2