#### Archived

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

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

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

## 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 on other sites
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 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 on other sites
you need to #include

Which is the input and output.

int main()
{

}

dont put
int main();

##### 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 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 on other sites
Yeah ive seen that about in other peoples code, but what do all those arguments mean???

##### Share on other sites
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 on other sites
"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 on other sites
Yeah, it pisses me off to no end to see people (even those who are supposed to know what they''re talking about) call things DOS just because they''re character mode or because they see a command-line interface.

##### Share on other sites
well, when I run a java program and the console pops up, guess what the icon in the corner is. Yep, the interlocking MS DOS icon. When I go to the start menu (and I call the task bar the start bar, which is wrong too) and open up the console it not only has the icon but it also says MS DOS as the window name. I don''t recall what my C window says but I''m guessing it says DOS too. DOS might have originally been an operating system but now the name is used for any console. Words change meaning, generally in illogical ways but that''s how things go.

##### Share on other sites

Um. It''s the label on the console because the console is the shell used in which to run your program. Windows happens to use MS DOS (yes, the operating system) or an emulator thereof... it gives a console program an appropriate context in which to run. The fact that MFC apps, unless you change them, have the generic "MFC" icon in the upper left corner of the window doesn''t mean that MFC has suddenly stopped being an API and has miraculously morphed into a new type of console or window or whatever.

-fel

##### Share on other sites
In both Windows 9x and NT (and all variants) a Win32 console app does not use DOS (9x does to no further a degree than the rest of the OS). In NT this is obvious in that you''ll never see a virtual DOS machine process spawned when you run a console app. Furthermore, Win32 console apps use a completely different executable image format than DOS apps--the same one as Win32 GUI apps.

##### Share on other sites
hehe
no offense dude
im a beginner at programming too
sorta
i learn a bit of visual basic and i just started c
im doing c++ next
but!
ive got teach yourself c in 21 days
and it DOES tell me that the numbers are for reference only
So im gonna guess that ures does too.
Which would make you...stupid for not reading it..
hehe
no offense
Everyone does it
I copied the code that i was supposed to correct first off
but its still funny.
: )

##### Share on other sites
Like I said, merlin, "or an emulator thereof".

##### Share on other sites
Fel, you said that it [Win32 console apps, I''m assuming] either uses DOS or an emulator. And I''m saying that it either barely uses DOS (this is only a technical correctness in Windows 9x) or not at all (as things should be, as they are in NT, since the executables have no relationship with DOS other than the tiny stub at the beginning to give you that message if you try to run it on DOS).

##### Share on other sites
it all depends on what compiler you are using. MSVC++ seems to open in a DOS console, if you use a borland compiler however, it doesn''t use dos at all, nor does it even look like it.

##### Share on other sites
#include

void main ()
{
cout << "Hello World!" << endl;
return;
}

X-Fe@R... is back!
------------------

##### Share on other sites

int main(int argc, char** argv)

"argc" is the number of command line parameter sent to the program. "argv" is an array of strings that are the parameters. I know this because the first C++ program I ever wrote printed a list of command line parameters given to the program to a DOS window. I saw the argc and argv and wondered what they were (I never write code I don''t understand) and didn''t give up until I understood them!

##### Share on other sites
Does anyone remember what DOS stands for? Disk Operating System. For the millionth time, guys, just because it''s a character-mode window or a command-line interface does NOT mean it''s DOS. A command-line interface is not an operating system. Nor is a character mode application an operating system. The operating system is simply a program and all of the parts it uses to perform basic operations on the computer. The interface is a separate thing. Do we call Linux''s Bash by the name DOS? Of course not, because we know that Linux is an operating system and Bash is the interface and it just so happens to be character mode and command-line base. The same thing is true of the Win32 Console. Win32 console apps intrinsically have NOTHING to do with DOS. The absolutely ONLY relationship is the fact that Windows 9x uses DOS (an operating system) for some of its internals, but it''s equally true of both GUI and console apps. If you analyze both GUI and console apps, you will see absolutely no DOS API calls, but only Win32 API calls. Why is this? Because it has nothing to do with DOS.

Win32 console apps have nothing to do with DOS; they use 0 DOS API calls.

The command line in Windows is not DOS; it is the Win32 console. That is the proper name. How the console is implemented internally is a separate matter.

Stop calling it DOS, guys, before you give me a cardiac.

##### Share on other sites
Do any of you people call the OS/2 command line DOS? No, because OS/2 is OS/2 and it''s console is the OS/2 operating system. Same with Win32.

##### Share on other sites
If you think about it for a sec, DOS is part of Windows. Ever notice when it starts up? They just took out all the 16 bit real mode stuff, made it preemptive, and slapped a GUI on it. Nothing new there. (Except NT and 2000)

##### Share on other sites
As I said, the implementation of the OS has nothing to do with the apps themselves. Win32 console apps make no DOS calls, therefore they''re not DOS apps.

Think of it this way. Indeed, Windows 9x uses DOS as part of its implementation (not all). But Win32 console applications DO NOT. This is evident in that you can run the same Win32 console app on both 9x and NT, unmodified. NT implements DOS only as a VM for DOS apps, yet when you run that console app, no VDM is spawned. Why? Because it has nothing to do with DOS. If the app had some ties with DOS, NT would have to spawn a VDM in order to run it.

What defines what platform an application uses--Win32, DOS, OS/2, Linux, etc--is which API is uses. If it makes DOS calls, it''s a DOS app. If it makes Win32 calls, it''s a Win32 app. If it makes Linux calls, it''s a Linux app.

Win32 console apps make only Win32 calls, just like Win32 GUI apps.

Win32 console apps themselves have nothing to do with DOS. If they did, you''d be able to have them run identically on a pure DOS installation.