Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

rodneyldixon

Hello World (First C++ Program) Help!!

This topic is 6300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You see, I got this e-book from www.informit.com, and it's called Sam's Teach Yourself C++ in 21 days Second Edition, and in Day 1 Chapter 8, it talks about writing your first C++ program, a traditional Hello World. And when I typed in the code for displaying Hello World in Dos, using Dev C++ 4.0, I get a error and it saids in the compiler output, " parse error before `1'. Here's the code that I typed in: 1: #include 2: 3: 4: int main(); 5: { 6: cout <<"Hello World!\n"; 7: return 0; 8: } Question 1: What is the problem? Also, all I am learning is how to program text in Dos. Question 2: So how can this be helpful to me if I want to do C++ programming in Windows? (making games, programs, etc...) Do I need to learn this? Because if I don't need to learn this, I would be gladly to move on to learning to program C++ in Windows first instead of learning to program text in dos. Question 3: Also, can I get a tutorial or e-book that would teach me to program C++ in Windows? (on the internet or downloadable) Question 4: And can I get a tutorial or e-book that would teach me to write C++ games & programs in Windows? (on the internet or downloadable) So please answer all my questions. Not just one, but all of them so I can move on and stop asking questions here about, can I make this or that, because this is a forum to post questions if you get stuck in compiling, debugging, writing code, etc.... everything besides how to make something. Thanks! Edited by - rodneyldixon on April 21, 2001 12:29:43 PM Edited by - rodneyldixon on April 21, 2001 12:35:56 PM

Share this post


Link to post
Share on other sites
Advertisement
one problem is in sam''s teach yourself... seriese the lines are numbered, but in c++ they aren''t, the publiser just does that so it''s easier to type in the code without loosing your spot.

seccond, int main() should not have a ; after it.

third, i assume that you have or after #include and the forum just cut it off for some reason, if not add one of them.

hope this helps.

Share this post


Link to post
Share on other sites
ive just started as well and im using the same book but i thought i should reply. the output in the book is simple dos text but it teaches you all the basics of programming like functions and objects and stuff. you need a good knowledge of programming before you can start on different input and output and graphics and stuff

when youre happy with c++ just get another book specialising on games. i got Windows Game Programming for Dummies - ignore the dummies bit, its a good book. it teaches you everything you need to know to make simple 2d games using direct x, including bonus chapters on stuff like AI. it also comes with a cd containing a direct x development kit and some shareware programs that might be useful (paintshop pro and sound forge and stuff) so all you need is a good copiler and youre set

Share this post


Link to post
Share on other sites
Hi, I am no expert... I have had only two semesters of c++ but I certainly know the Hello World stuff...

I don't know the difference between writing "DOS text" and "Windows C++" - as far as I know they are the same thing. C++ is C++. Perhaps there are different functions and included you can use for specific purposes, but if there is a major difference between programming C++ in DOS and Windows then someone should clear me up on it...

As far as your code goes:
Do not number your lines... I know the book probably does and so does my teacher on handouts, but thats only so the teacher can tell you to look at a certain line for help...
You have the #include call but you don't include anything... I figure thats because the editor deleted it because you encapsulated it with "<" and ">" From what I know you need to say: #include [iostream.h] (using "<" and ">" instead of [ and ])... The iostream header file contains the stuff you need to use the "cout" and other input/output commands...

Also, I know books and stuff like to use int main() - but usually I make my main functions void... You don't have to return anything. Like the guy above said, don't put a semi colon after you main function... Your code should look like this:

#include [iostream.h] //where the ] and [ are > and <...

void main()
{
cout << "Don't type HELLO WORLD it is cliche'. Use something else." << endl;
}

\n ends a line. I have always used endl (end line). It does the same thing, but keeps it out of the quotation marks and makes it easier to follow...

For question 2: You need to learn everything you can about c++ if you want to program games. From what I have gathered from other people, game programming is some of the hardest programming out there. You certainly need to learn the basics before venturing into game programming. Input and output and using functions are basic, fundamental and crucial parts of programming, so I imagine you need to learn everything in order to make games...

Uhm for question 3: I learned c++ in computer science class. I learned that way with a text book. I am sure there are lots of book and articles on the subject. If nothing else goto google.com and do a search on online c++ tutorials...

Question 4: I do not know of a book for c++ game programming... I am using a book called "Tips of the Windows Game Programming Gurus"... It's written for C/C++ users (but MOSTLY for C), but it's not terribly difficult to port over the parts to C++... However, I am just starting our in game programming and haven't even written one windows game yet, so I hope some of this is helpful and not worthless, hehe... Good luck!

-ts



Edited by - TossSalad on April 21, 2001 10:21:49 PM

Edited by - TossSalad on April 21, 2001 10:24:05 PM

Share this post


Link to post
Share on other sites
I have to disagree with TossSalad about the void main() thing. Whether you return anything or not, this is how one should define the main function: int main(int argc, char** argv). Don''t worry about what that stuff is, but I''d suggest getting into the habit of doing it that way because that''s what the standard says is the correct way to do it.

Share this post


Link to post
Share on other sites
Yeah ive seen that about in other peoples code, but what do all those arguments mean???

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
riddle me this, i can write the same program under linux. is it considered a dos app? now think about that question the next time you decide to call your programs "dos" apps. It only becomes dos specific when you start calling os interrupts and actually compile it into a dos executable (yes windows and dos headers are different and VC++ console apps are still 32bit windows programs), which requires an older 16bit compiler. You''ll notice when you call interrupts under a Win32 "console" application that windows tends to give you a BSOD or something similar. Thats because you are trying to obtain ring-0 privleges with your ring-3 application, and windows doesnt like that and will let you know (good programming). If you want to gain access to hardware directly under windows, then learn to write device drivers, VXD''s that operate on ring-0, or use the API''s microsoft wrote for those exact purposes (Win32,DirectX). Anyhow, the point is there is a definite difference between a pure dos application, and a 32bit console application.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"Question 1: What is the problem?"

like others have said, you''ve got two problems:
you are numbering the lines and you have a ; where it doesn''t belong

"Question 2: So how can this be helpful to me if I want to do C++ programming in Windows? (making games, programs, etc...) Do I need to learn this?"

yes, sadly the best way is to start small and work your way up. The temptation is to jump ahead a couple chapters, but you''ll always have that temptation, even when you get to the end of the book and you''ll want to buy another before you are even done with the first. I have so many books already, I want more but I really haven''t fully read the ones I have. You can also take it for granted that I am biting off bigger things that I should, I almost never get anything finished, only the tiny projects they have me do for school. I know it hurts but just do the small stuff and slog though it in order.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!