C++ Help!!! - DFWstangs Forums
 
LinkBack Thread Tools Display Modes
post #1 of 18 (permalink) Old 10-28-2003, 11:28 PM Thread Starter
 
Join Date: Aug 2003
Posts: 1,080
C++ Help!!!

alright i took ap computer science in high school (didn't do to well haha) and i recently picked up where i left off and i can't seem to get anywhere in C++...


I'm using Dev-C++ and i'm running on Windows 2000 prof. after i go thru all the steps

#include (iostream.h)--- *replacing the ()'s with the < >
#include (stdlib.h)--- *replacing the ()'s with the < >

int main()
{
cout << "text here";
return 0;
}

nothing happens. it will compile and when i try to execute it i get nothing! now i've searched the web on other message boards and i get no good responses. so i've tried other things and read the compilers FAQ it tells me to do this:

#include (iostream)--- *replacing the ()'s with the < >
#include (stdlib)--- *replacing the ()'s with the < >

int main()
{
cout << "text here";
system("PAUSE");
return 0;
}

and with that it will compile and execute but the only thing it says is, "Press any key to continue..." after i press a key it just exits like normal. ANY HELP ON THIS SUBJECT WILL BE GREATLY APPRECIATED!!!

Last edited by stevinwayne; 10-28-2003 at 11:31 PM.
stevinwayne is offline  
Sponsored Links
Advertisement
 
post #2 of 18 (permalink) Old 10-29-2003, 12:10 AM Thread Starter
 
Join Date: Aug 2003
Posts: 1,080
oh come on i know someone on this board is a C++ expert






especially the ones that are on at 1:14 am
stevinwayne is offline  
post #3 of 18 (permalink) Old 10-29-2003, 07:48 AM
Timmay
 
Tiny Tim's Avatar
 
Join Date: Aug 2001
Posts: 4,898
your syntax looks fine to me. I doubt that is the problem

Last edited by Tiny Tim; 10-29-2003 at 07:51 AM.
Tiny Tim is offline  
 
post #4 of 18 (permalink) Old 10-29-2003, 12:03 PM
 
Join Date: Oct 2003
Posts: 49
getch();
iyaracingdotcom is offline  
post #5 of 18 (permalink) Old 10-29-2003, 03:26 PM
 
Join Date: Oct 2003
Posts: 49
#include (iostream.h) /* should be <> */
#include (conio.h) /* should be <> */

int main()
{
cout<<"Hello World!";
getch();
return 0;
}
iyaracingdotcom is offline  
post #6 of 18 (permalink) Old 10-29-2003, 07:25 PM Thread Starter
 
Join Date: Aug 2003
Posts: 1,080
maybe it's just my computer???

with the getch(); in there and including the conio.h it says "implicit declaration of function 'int getchar(...)' "
stevinwayne is offline  
post #7 of 18 (permalink) Old 10-29-2003, 09:52 PM
 
Join Date: Mar 2003
Posts: 1,394
you tested the code i wrote and it didnt work?
xtremcoder is offline  
post #8 of 18 (permalink) Old 10-29-2003, 10:20 PM Thread Starter
 
Join Date: Aug 2003
Posts: 1,080
yeah that code didn't work either...
stevinwayne is offline  
post #9 of 18 (permalink) Old 10-30-2003, 08:22 AM
No Cerveza... No Trabajo
 
01WhiteCobra's Avatar
 
Join Date: Jun 2002
Location: Where's my beer?
Posts: 21,924
use std::cin.get().

Works better and doesn't rely on any DOS crap.

Don't use conio.h, it's Windows specific not standard C/C++. Replace the () with angle brackets.

#include (iostream)
#include (cstdio)

instead of

#include (iostream)
#include (conio.h)

The .h isn't required IF it is a standard C/C++ library.

If you are dead bent on using getch(), then you will need to add:

#include (stdlib.h)

to your includes, most likely.

All this off the top of my head. I have written a hello world program in about 20 years.
01WhiteCobra is offline  
post #10 of 18 (permalink) Old 10-30-2003, 04:30 PM
 
Join Date: Mar 2003
Posts: 1,394
what i wrote is for DOS - sorry.
xtremcoder is offline  
post #11 of 18 (permalink) Old 10-30-2003, 04:41 PM
Good times
 
SVT Lurch's Avatar
 
Join Date: Nov 2002
Location: Texas
Posts: 9,488
shouldn't it be void main()

n/a
SVT Lurch is offline  
post #12 of 18 (permalink) Old 10-30-2003, 04:47 PM
R.E.N.G.
 
Turd's Avatar
 
Join Date: Jul 2001
Location: E = MC Vagina
Posts: 2,919
Quote:
Originally posted by BossShinoda
shouldn't it be void main()
not with the return
Turd is offline  
post #13 of 18 (permalink) Old 10-30-2003, 04:50 PM
 
Join Date: Mar 2003
Posts: 1,394
void doesnt return a value, int does...which is why you return 0 (false)
xtremcoder is offline  
post #14 of 18 (permalink) Old 10-30-2003, 07:27 PM
No Cerveza... No Trabajo
 
01WhiteCobra's Avatar
 
Join Date: Jun 2002
Location: Where's my beer?
Posts: 21,924
Quote:
Originally posted by BossShinoda
shouldn't it be void main()
The ISO standard for C++ does define main returning int. But, unfortunately, the C ISO standard doesn't and allows for other return values including void.

But the C ISO standard dorks say that not returning int is "undefined". Meaning, depending on compiler vendor, it could shit on your system, or maybe it won't.

int main() is a better all-around solution.

This message has been brought to you by Geeks For A Better America.
01WhiteCobra is offline  
post #15 of 18 (permalink) Old 10-30-2003, 08:26 PM
R.E.N.G.
 
Turd's Avatar
 
Join Date: Jul 2001
Location: E = MC Vagina
Posts: 2,919
Quote:
Originally posted by xtremcoder
void doesnt return a value, int does...which is why you return 0 (false)
that was my point, it's been awhile for me, but using a return in a void funtion is a no-no isn't it? so if he would have to remove the return to switch to void right? this makes me want ot start playing around with some code again.
Turd is offline  
post #16 of 18 (permalink) Old 10-31-2003, 06:20 AM
Googlist-Wikipedian
 
Hunt4m3x's Avatar
 
Join Date: Jul 2002
Location: de_aztec
Posts: 4,814
Quote:
Originally posted by Turd
that was my point, it's been awhile for me, but using a return in a void funtion is a no-no isn't it? so if he would have to remove the return to switch to void right? this makes me want ot start playing around with some code again.
yes, void functions don't return thing anything.

2005 Infiniti G35 Sedan Ivory Pearl Premium

2006 Infiniti FX45 Liquid Platinum

2010 Polaris Ranger RZR S Orange Madness







Ban count: 2
Hunt4m3x is offline  
post #17 of 18 (permalink) Old 11-03-2003, 04:33 PM
Time Served
 
Join Date: Jan 2002
Location: Bedford, TX
Posts: 761
Are you trying to run it from Windows based program? Sorry, not familiar with Dev-C++. If you are the reason why you're not seeing anything is that it runs on DOS prompt and since Windows opened it, it will be closed after execution. Locate the EXE that was created and run it from DOS prompt that you opened (start -> run -> type "command"), that should show you the results.

Last edited by Sami; 11-03-2003 at 04:35 PM.
Sami is offline  
post #18 of 18 (permalink) Old 11-10-2003, 10:57 PM
Ghetto Vaquero
 
BlueStang2k's Avatar
 
Join Date: Oct 2000
Location: Groovy Grove
Posts: 1,303
Using Visual C++ this code worked well.

#include
#include

int main()
{
cout<<"Hello World!\n";
return 0;
}
BlueStang2k is offline  
Sponsored Links
Advertisement
 
Reply

Bookmarks

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the DFWstangs Forums forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may 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

 
For the best viewing experience please update your browser to Google Chrome