Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [sample code] Hello World
Index -> Programming, C++ -> C++ Tutorials
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tony




PostPosted: 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 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 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)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Asok




PostPosted: Wed Mar 12, 2003 2:47 am   Post subject: (No 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
Tony




PostPosted: Wed Mar 12, 2003 9:07 am   Post subject: (No 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)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
azndragon




PostPosted: Tue Mar 18, 2003 4:51 pm   Post subject: (No 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?
Tony




PostPosted: Tue Mar 18, 2003 5:41 pm   Post subject: (No 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)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Asok




PostPosted: Tue Mar 18, 2003 6:26 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 18, 2003 6:35 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 18, 2003 6:48 pm   Post subject: (No 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.
Tony




PostPosted: Tue Mar 18, 2003 7:13 pm   Post subject: (No 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?!
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




PostPosted: Tue Mar 18, 2003 8:49 pm   Post subject: (No 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 .
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Tony




PostPosted: Tue Mar 18, 2003 9:02 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
void




PostPosted: 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.....
Asok




PostPosted: Sun Apr 06, 2003 8:09 pm   Post subject: (No 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
Blade




PostPosted: Sun Apr 06, 2003 8:53 pm   Post subject: (No subject)

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




PostPosted: Sun Apr 06, 2003 9:01 pm   Post subject: (No 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).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 3  [ 35 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: