URI:
   DIR Return Create A Forum - Home
       ---------------------------------------------------------
       The New DS computer forum!!
  HTML https://dscomp.createaforum.com
       ---------------------------------------------------------
       *****************************************************
   DIR Return to: C++
       *****************************************************
       #Post#: 285--------------------------------------------------
       Tutorial #2 - Hello World!
       By: Hondaman Date: October 8, 2010, 5:42 pm
       ---------------------------------------------------------
       [center]This is the first tutorial where you wll actually learn
       to code.
       This tutorial will teach you how to output basic text on the
       screen, compile and run it.[/center]
       [font=Trebuchet MS]The script -[/font]
       In your new source file you just created you will now enter the
       following line.
       [code]
       #include <iostream>
       [/code]
       This is the Standard way of including a header file in C++.
       #include Is telling the compiler to use the file in inbetween
       the greater than and less than signs '<>' is the filename.
       in this case it's 'iostream' which has all of the basic
       functions built in and will be in all of our scripts.
       The next line you will enter is
       [code]
       using namespace std;
       [/code]
       There is a standard library called namespace.
       This library is important if you don't want to have to make your
       code longer.
       (I'll explain when it comes to text output)
       After this you start the main function
       In the main function, this is where the compiler will execute
       code.
       if you were to put code outside the function the compiler
       wouldn't know what to do with it.
       [code]
       int main()
       {
       
       }
       [/code]
       'int main()' is the start of the main funcrtion
       'Int' is the type of function and 'main' is the name of the
       function.
       but the '()' parentheses are for arguments, these are not needed
       right now so I won't explain them just yet.
       then inside the '{}' curly brackets is the code itself.
       This is what the compiler will look in for what it is supposed
       to output or do.
       Now for outputing the text.
       outputing text isn't as simple as you think it would be.
       you cannot just type "Hello world!" although that would be
       easyer.
       The code is alot harder to understand and write.
       [code]
       cout << "Hello World!" << endl;
       [/code]
       'cout', is the command for the compiler output something.
       This basicly means Compiler output 'cout'.
       Then there is '<<', this is the insertion operator and it is
       necessary.
       after the instertion operator you can type what you want in
       speech marks and this is what the compiler will output.
       and finally you see another insertion operator and 'endl;'
       'endl;' is the function for end line, this means that if you
       extend the code,
       everything else will be outputed on another line.
       and the semi-colon ';' is important, without it the compiler
       will not run the code.
       the colon tells the compiler you are done with that line of
       code.
       The last thing you need to do is make the program pause so you
       can look at the output and tell it that it's done.
       to do this put the following code in the function below 'cout <<
       "Hello World!" << endl;'
       [code]
       system ("pause");
       return 0;
       [/code]
       the first line 'system ("pause");' tells the compiler to pause
       once its ran the script.
       This will end the program with 'Press any key to continue...'
       automatically.
       and 'return 0;' tells the compiler its done and the program has
       been successful.
       [font=Trebuchet MS]Compiling and Running the script -[/font]
       Now that you have your script,
       click File and save your document. (or press CTRL and S)
       Then there is an Icon in the toolbar with four boxes on it.
       Click that and the program will compile.
       C++ is a language that has to be compiled into machine code
       beacuse it is native to your computer.
       This is why you had to download the Dev C++ compiler.
       If you tried to run the code without the compiler, it would just
       be an unknown file type.
       Once your program has compiled,
       It should run automatically.
       If it doesn't, find the folder you saved your 'script1.cpp' and
       you should have a new file there called
       'script1.exe'
       '.exe' is the extention for an executionable file, if you have
       this file the program was a success.
       And now you can play around with what I've taught you and read
       my next tutorial.
       [center]<< Previous
  HTML http://www.dscompforums.tk/c/tutorial-1-getting-a-compiler/msg284/?topicseen#new<br
       />  |   Next >>
  HTML http://www.dscompforums.tk/c/tutorial-3-extending-the-hello-world!-script/[/center]
       *****************************************************