Computer Science Canada

[sample code] Hello World

Author:  Tony [ Wed Mar 12, 2003 12:42 am ]
Post subject:  [sample code] Hello World

hey, we all have to start somewhere, dont we? You usually start learning every single language with a hello world program. Well other then turing. I started that off as an animation program where I could draw boxes in different places... I wonder if my teacher still has my animation stored somewhere Confused I'd have to ask, but after march break Wink

anyway, here's how Hello World works in C++

code:

#include <iostream>
using namespace std;

void main()
{
     cout << "Hello World!\n";
}


This works in MS Visual C++ 6... so if you copy paste the code and it doesnt work... its your compiler Evil or Very Mad

Now for some explanation.

#include <iostream> its a header file... works much like include in turing and allows you to add parts of code to your program. Most of the commands in C++ are functions stored in those header files and must be added to work properly. It might be a bit confusing at first, but unlike turing that adds EVERY SINGLE FILE IT CAN FIND, your program size is much much less. This particular headerfile allows you to use intput/output.
Note: You might have to use #include <iostream.h> depending on the compiler

using namespace std; a standart... basically tells the compiler you're using the namespace standart for programming. More on that later.

void main() a must have function. Its the first one to be executed and the program will not run unless you have it somewhere. void means it doesnt return a value. More on that in functions tutorial.

{ .. } those brakets engulf the content of the function and shows compiler where it begins and ends.

cout << "Hello World\n"; cout stands for Counsel Out. And acts much like put in turing or print in VB. cout is followed by "<<" and then text to be outputed. << acts like a comma (turing) or & (VB) that adds text parts together. Same as cout << "Hello " << "World\n";
"\n"
is a new line character, makes courcor move onto the next line. In comparison to turing where you have to add ".." to keep output on same line, in C++ you use "\n" character to force output onto the next line.

A turing equivalent of same program is
code:

put "Hello World"


Right now the difference between programming languages is balance between simplicity and power of the language. Such as you get unlimited power while programming in binary, yet understanding of it is close to 0.

C++'s advantage over turing is speed and power, and with all that, its not that much more complex. Just have to get used to putting all those {}s and ;s Wink

For such a little program this is a hell lot of explanation, but when learning any language, its not about momorizing the syntax, its about understanding it. And I hope to see you guys in C++ area more often 8)

Author:  Asok [ Wed Mar 12, 2003 2:47 am ]
Post subject: 

I would like to add, for those of you who are feeling too lazy to copy and paste Rolling Eyes . C++ comes with a Hello World wizard. Create a new workspace, make it a Win32 Console Application, on the next screen select "Hello World" Program, click finish and ta-daa! Your very own Hello World program without having to type a damn thing! (yes I know you have to type the name of the workspace but you'd have to do that either way.) Who ever said C++ was hard? Wink

Author:  Tony [ Wed Mar 12, 2003 9:07 am ]
Post subject: 

umm... well... yes..

though thats Visual C++ 6... I donno about other compilers Wink

but ya, its gonna basically type up the code for you. Instead of writing up some tutorials in MSDN, smart people over at Microsoft desided that it would be better to make a wizzard for creating a "Hello World" program for you....

it works like this

"would you like the wizzard to create a Hello World program for you?"
"yes/no"

Confused thats as far as it gous. But hey, if you dont understand how that works I've got a full explanation of the program above /\ 8)

Author:  azndragon [ Tue Mar 18, 2003 4:51 pm ]
Post subject: 

Quote:
This works in MS Visual C++ 6... so if you copy paste the code and it doesnt work... its your compiler


Okay, so if different compilers have different codes, then how can you learn C++ effectively? Or are you just suggesting that the compiler does not work properly? On a side note, how much does a decent comiler cost, and how much is a C++ manual?

Author:  Tony [ Tue Mar 18, 2003 5:41 pm ]
Post subject: 

I'm just saying that different compilers differ a bit. Such as most of modern programs would not compile using an ansient 16-bit DOS compiler. You gotta get a 32-bit one.

Also they differ in things such as headers. In some compilers you'd have to include full file name, while in compiler like VC++ you dont need the extension.

There're aren't many differences, much like turing 3.1 vs 4.0 Mostly just editors.

I donno about the cost of profesional compiler. About $200 but thats a wild guess so I might be way off. Books range in $70-100 but you can use MSDN for free at www.msdn.microsoft.com and perhaps even download it (though it will be installed with compiler... or atleast it should)

Author:  Asok [ Tue Mar 18, 2003 6:26 pm ]
Post subject: 

Your best bet is to get it from your school if they allready have a distribution license.

Author:  azndragon [ Tue Mar 18, 2003 6:35 pm ]
Post subject: 

My school's too cheap to use C. Most advanced language they use is VB. And plus, these teachers share chalk! Shocked

Author:  Asok [ Tue Mar 18, 2003 6:48 pm ]
Post subject: 

oh man, I bet ur principal has a really nice office. he could probably sell some of those books in there for some damn chalk.

Author:  Tony [ Tue Mar 18, 2003 7:13 pm ]
Post subject: 

i donno Asok... Sure, Wayne has lots of books that are there just for the heck of it... and a huge TV too Wink Donno about other schools though Confused

but ya, good point... what kind of 3rd world country school is it that they dont have enough chalk?!

Author:  Dan [ Tue Mar 18, 2003 8:49 pm ]
Post subject: 

your school has a pricesplas ofices Shocked , wow.


in my school they got like 3 guiinese ofices they use for everyting, lol, including pricpale. in there they got 2 chares (cheep ones) and a old computer.


at least your school has chalk Sad


well my school may have chalk, but some days when i am in the computer lab with computers that just have win 3.1.1 and procsers that i have never hread of it felles that way Crying or Very sad .

Author:  Tony [ Tue Mar 18, 2003 9:02 pm ]
Post subject: 

well compsci.ca was leargely created for the purpose of teaching canada about computers... cuz we got cases such as Dan's... I got a feeling that as soon as we'll start compiling turing online... our servers will overload Shocked

Author:  void [ Sun Apr 06, 2003 7:47 pm ]
Post subject:  CHALK ME

whoa...im boared today...i've been literally EVERYWHERE on this site...and i've left a comment wherever i felt neccesary..heheheheh....yea...my skool is pretty cheap..the thing is...our library is BEAUTIFUL...the entrance is sooooo cool and thats the only part of the skool that actualy looks good the rest was designed by some crackhead who didnt have his daily dose yet....guess what you see on the brocure for our school ??? one picture....c'mon u know it...it the LIBRARY!!! thats right...our beautiful library...shos u how cheap our school is....actualy some rich@$$ donated a whole GCI computer lab to our school in order to graduate his daughter with a 90% average....changing topics
thank god that my cs teacher is cool...he has almost every compiler in the world on one of his computers...and one day he brought it to schoool..hooked it up and he charged us $5 for a CD with all the compilers we could fit on it...THANK GOD FOR BURNERS!!!!! i kno that what he did was prolly illegal but oh well...its like having Kazaa...without the insecurity and the eating up of bandwidth.....

Author:  Asok [ Sun Apr 06, 2003 8:09 pm ]
Post subject: 

What he did was illegal and compsci.ca does not endorse such actions even though I am personally not directly opposed to them.

just hope the RCMP doesn't read these forums Wink

Author:  Blade [ Sun Apr 06, 2003 8:53 pm ]
Post subject: 

yea, if i knew someone that did that... i would feel insecure about sayin somethin about it... damn those conciences... Rolling Eyes

Author:  Tony [ Sun Apr 06, 2003 9:01 pm ]
Post subject: 

has anyone played in Metal Gear Solid 2?

if not, you should. It has a really interesting storyline about internet sensership, freedom of speech and stuff like that.

You can rent it for PS2 or Xbox and beat the game over the weekend (if you stay up long enough that is).

Author:  Dan [ Sun Apr 06, 2003 9:36 pm ]
Post subject: 

any way on the subject of computer crimes....

*dan runs out door, jumps in to car and divers away*

THEY WILL NEVER GET ME NOW, HA HA HA HA. Laughing

Author:  Asok [ Sun Apr 06, 2003 9:55 pm ]
Post subject: 

lmao Laughing

Author:  void [ Mon Apr 07, 2003 7:04 pm ]
Post subject:  hahahha

lmfao...with a name like "hacker dan"...they'll never suspect you....even tony is less suspicious than you....even tho it says "hacker god" under both your names.....i would say that the RCMP have better things to do than read our forums...but im scared that i might be lying....no marajuana busts lately

Author:  Asok [ Mon Apr 07, 2003 11:47 pm ]
Post subject: 

*imagines photo of RCMP on horseback*

no I don't believe they have anything else better to do Razz

Author:  Dan [ Tue Apr 08, 2003 12:19 am ]
Post subject: 

i dont care, they got nothing on me! i tell you nothing Wink

besides it's not the RMCP that will be affter me Twisted Evil

my plane was to hide in plane site, i mean who whode have though to look on a porgmaing borad for a hacker? and puting the name as hacker dan and hacker god will throw them off becuse they will say "no, they cant be so nuts to go and tell us they are hackers". lol

any way the worad "hacker" dose not acualey all ways mean some one who "breaks" in to computers or make virus. it can also mean some one who makes computer porgames for run or some one who knows aboulsey everyting about a crent progaming lagnuge or pice of software like an os.

hacker vocab:

cracker - is some one who breaks in to computers and/or gets pasworads to things

perking (not spelled right) - is the use of tones and such to get free long distace. also can include dialing random phone numbers to find computer severs.

vrius making (cant think of a better name) - making diticutive porgames, ushley ones that replacet and infect more computers. can also include trogens (progams that alow actes to the computer they are on), logic bobms, ect.

kiddy hackers - a new genration of hackers that dont necraly know a lot and just use other poleops hackng apps to do damgae, this gourp is one of the most coman now and is messing up the net with no regauged for anyting. this can also inluced virus making progames.

well thats todays look in to the wonderfull under worald of hacking for today if any one whonts to know some more ("dont ask how do i hack") about this worald just ask and aslong as it is not going to get me in shit i will tell you what i know 8)

Author:  Asok [ Tue Apr 08, 2003 1:12 am ]
Post subject: 

lol kiddy hackers, reminds me of Back Orfice, fucking moron child used that on me, deleted the trojan and packeted the fuck out of his modem *tracer program monitored the connections going into my comp so I just took his IP from there* His parents then called me threatening to sue (I shit you not) because they were paying for cable internet access which I was now disrupting. I told them to stop being neglectant parents and they would recieve their internet connection back I damn well feel like it (a week later when a rebooted and forgot to resume sending packets) but I made my point. Don't take crap from morons, revenge is ever so sweet.

Author:  void [ Tue Apr 08, 2003 6:51 am ]
Post subject: 

hey i used ta be a kiddy hacker....in gr.7 ...t was fun coz none of our skool comps had nanny's back then so when the attacked retaliated...our school network was fu$ked up the @$$. Twisted Evil ..it was quite entertaining....but then i entered the world of programmig Razz in gr.9 and have never looked back since.....(prolly coz toronto and waterloo are quite the distance Razz)

Author:  Prince [ Tue Apr 08, 2003 10:22 am ]
Post subject: 

hey dan, is that "perking" supposed to b "phreaking" (heard of it sumwher, cant remember if its the same) cus if it is i saw it in the movie The Core... it was pretty damn cool... wish i knew how to do that Sad

Author:  Asok [ Tue Apr 08, 2003 10:30 am ]
Post subject: 

black box man, uses dial tones to call the number for you for free. My friend has one, I wouldn't reccomend it due to the average call costs $0.25 and the box cost like $120 so unless you plan on making some serious long distance calls from payphones it's probably not worth it.

Author:  Dan [ Tue Apr 08, 2003 4:07 pm ]
Post subject: 

PrInCe_ wrote:
hey dan, is that "perking" supposed to b "phreaking" (heard of it sumwher, cant remember if its the same) cus if it is i saw it in the movie The Core... it was pretty damn cool... wish i knew how to do that Sad


ya it is, i relay suck at spelling. phreaking used to be a lot more popualr back in the 70s - 80s when computer servers where not as sucure and most of them where diialed up to.

also wasninte it claled the bule box? any how dosen't matter you get the point.

Author:  PHP God [ Wed Jun 25, 2003 8:50 pm ]
Post subject: 

I may be off topic, lol, but this C++ business confuses me. Is there some application like WINoot I can use. I tried using notepad and a compiler but that takes too long. I want a program where I code, hit run, and let her fly. If it had an error report that would rock too.

Author:  Tony [ Wed Jun 25, 2003 11:57 pm ]
Post subject: 

you talking about editor... VC++ has one.

Author:  icemaster [ Sat Jan 24, 2004 6:03 pm ]
Post subject: 

oh yea Tony about Metal Gear Solid, i have the first one for ps one and when i got a ps2 i bought MGS2 it is freakin amazing i even played the latest version of MGS2, the one where u can skateboard and stuff, plus added VR missions, etc.

Metal Gear Solid is undoubtably one of my favourite games

Author:  wtd [ Mon Feb 09, 2004 1:53 pm ]
Post subject: 

I would recommend [url=http://eclipse.yearbookcentral.net/MinGWInstall/MinGW-3.1.0.exe]MinGW[/ur]. It's easy to run from the command-line, and you'll find a lot of people who can help you with errors, since GCC has a huge community.

Be careful of VC++, especially 6. It's not terribly good at implementing the standard, and version 6 in particular has trouble with anything involving templates.

code:
C:\> g++ hello_world.cpp -o hello_world.exe
C:\> hello_world
Hello world!
C:\>

Author:  netninja [ Wed Feb 11, 2004 9:05 am ]
Post subject: 

A game that can be beat in 2 days is not worth playing. Unless its really cool! And metal gear 2 isnt amazing. But i cant think of any amazing games right now either. Oh, and you actually sounded exactly like a blockbuster ad from tv or something Laughing

Author:  netninja [ Wed Feb 11, 2004 9:10 am ]
Post subject: 

Back on topic: Im having trouble actually getting my code written lol. I can write a small program, but i dont know where to write it. I have VC++ 4, and i have no idea where the code is supposed to be typed. I start off by > New > Project > empty project. Then after that, im stuck. Laughing

I also tried with workspace. The only thing that I can actually begin writing code is when i goto > new > files > c++ source, but then it complains i dont have a workspace. Then it asks me to make one, so i do. And thats it. After that, it says error. Doesnt work lol. I even tried with the simple hello world program, 100% theres no errors. And it says error....

Author:  Andy [ Wed Feb 11, 2004 10:46 am ]
Post subject: 

vc 4? get 6... and make console applications for ur simple programs

Author:  netninja [ Wed Feb 11, 2004 3:55 pm ]
Post subject: 

Ok, vc6 it is, I dont think ill be writing too many console programs though Laughing

Author:  Andy [ Wed Feb 11, 2004 4:37 pm ]
Post subject: 

its what its called... win 32 console application

Author:  McKenzie [ Wed Feb 11, 2004 10:15 pm ]
Post subject: 

Dodge is right, unless you have either a strong Windows programming background or a strong C++ background start with console.
As for where to code, once you have the new project go
File -> new -> C++ source (There are other ways of course)


: