Posted: 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 I'd have to ask, but after march break
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
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
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)
Posted: 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 . 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?
Tony
Posted: Wed Mar 12, 2003 9:07 am Post subject: (No subject)
umm... well... yes..
though thats Visual C++ 6... I donno about other compilers
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"
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)
Posted: 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
Posted: 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)
Posted: Tue Mar 18, 2003 8:49 pm Post subject: (No subject)
your school has a pricesplas ofices , 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
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 .
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Tony
Posted: 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
Posted: 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
Posted: 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
Blade
Posted: 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...
Tony
Posted: 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).