Acerthief
08-22-2007, 10:18 AM
Well, C++ eh?
Just a notice that this tutorial is for C++ PC not C++ PSP.
I'll figure out some time to do a lil PSP programming.
Anyways....
Set Up your enviornment:
Download "Dev-C++"(It's Free) HERE (http://prdownloads.sourceforge.net/dev-cpp/devcpp-4.9.9.2_setup.exe)
Install it, and open the program! Press Ctrl+N for a new source code sheet.
This is the code for today's tutorial:
//Lesson 1: Hello World!!
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout <<"Hello World" <<endl;
cout <<"Hell PS2--- Forum XDXDXD"<< endl;
system("pause");
return 0;
}
I'll teach new things with codes line by line. so you can get everything clear. it's almost the same as my book. :D
//Lesson 1: Hello World!!
See a "//" in the front? it means that this line is descriptions for the programmer to see. When the complier reads the "//" it will skip the line of code and start compiling the line after. After the // you can type anything you want.
The "//" is used for descriptions of only one line. When you go to the next line the compiler will start compiling again!
#include<iostream>
#include<cstdlib>
This two lines should always be written at the first of the program. no matter what.
These are called "Library". It's contains all the data for specific functions, like system() on line 9. we use "#include<Library_name>" to "specify" our libraries.
iostream - Short for "input/output stream" basically it contains most of the C++ input/output (keyin, show text, numbers on the screen) functions.
cstlib - Short for "Standard Library". Contains all the basic C++ functions, like system().
using namespace std;
I'll have to skip this for now, as this needs lots of explanation with advanced terms.
This line of code is also needed to be written as well. Write it after all the "#include<>".
int main(void)
This is the "block"(a term here!) and the main function where our main codes will be written. You'll see "{" on line 6 and "}" on line 11. In between {} are codes of the function.
The "int" in front means that the main function returns a "integer". (What's does that mean? You'll see Later 8) ).
There's a void in the () after main. void means "nothing", so here it means that the main function doesn't have any arguments needed or used.
cout <<"Hello World" <<endl;
cout <<"Hell PS2--- Forum XDXDXD"<< endl;
These two lines basically print the text.
cout (pronounced c-out) can be said as the device to print text on the screen. we use an "operator" (which is the "<<") and send the string of text on the right to the output device (cout in this case)
Put it another way: We put the string(characters, text) "Hello World" write to the cout device on the left.
endl simply means "end of line". (Like the "return/enter" button on our keyboard). The new string after "endl" will be printed on a new line.
When putting a string (string - characters, numbers, or text) you have to use a " at the front and end so the compiler knows that line of code is a string of text.
system("pause")
This is one of the most important functions to learn. This function tells the computer to pause the program/code until any key is hit. Why we need this?
DOS is set that when the program/code finishes running the window will automatically close. Like a small program like this the window would open and suddenly close so fast you could barely notice.
With this line added, and using this code for example, the program will pause after it pasted the "Hello World" and "Hell PS2--- Forum XDXDXD" text on so that you can see the results, and after pressing any key the program will continue and closes when it hits the end.
return 0
Remember "int main(void)"? it's sets that you need to return an integer for the function. Yup, now we're returning the main() function a 0! And hey, 0 is an integer, just what main() wants.
Basically this shows the main() that the code ends here.
It's needed at the last line of the main()! or else it's will fail when compiling.
You see a ";" at the end of each line? You can tell it's added at the end of every line of coding (the functions don't needed, because it has {} to show the area of the code.) Why do we need that?
When we compile this is how the computer reads the code:
cout <<"Hello World" <<endl;cout <<"Hell PS2--- Forum XDXDXD"<< endl;...
Everything in one line. With a semicolon the compiler knows when one line of code ends. Forgetting to put a ; can cause a LOT of trouble! Always double check before compiling.
Now Press F9 to compile. You'll need to save the source code before compiling. name anything you want, and save anywhere you like, and an .exe file will be made with the same name of the source code.
Enjoy Your First C++ program!!!
Just a notice that this tutorial is for C++ PC not C++ PSP.
I'll figure out some time to do a lil PSP programming.
Anyways....
Set Up your enviornment:
Download "Dev-C++"(It's Free) HERE (http://prdownloads.sourceforge.net/dev-cpp/devcpp-4.9.9.2_setup.exe)
Install it, and open the program! Press Ctrl+N for a new source code sheet.
This is the code for today's tutorial:
//Lesson 1: Hello World!!
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout <<"Hello World" <<endl;
cout <<"Hell PS2--- Forum XDXDXD"<< endl;
system("pause");
return 0;
}
I'll teach new things with codes line by line. so you can get everything clear. it's almost the same as my book. :D
//Lesson 1: Hello World!!
See a "//" in the front? it means that this line is descriptions for the programmer to see. When the complier reads the "//" it will skip the line of code and start compiling the line after. After the // you can type anything you want.
The "//" is used for descriptions of only one line. When you go to the next line the compiler will start compiling again!
#include<iostream>
#include<cstdlib>
This two lines should always be written at the first of the program. no matter what.
These are called "Library". It's contains all the data for specific functions, like system() on line 9. we use "#include<Library_name>" to "specify" our libraries.
iostream - Short for "input/output stream" basically it contains most of the C++ input/output (keyin, show text, numbers on the screen) functions.
cstlib - Short for "Standard Library". Contains all the basic C++ functions, like system().
using namespace std;
I'll have to skip this for now, as this needs lots of explanation with advanced terms.
This line of code is also needed to be written as well. Write it after all the "#include<>".
int main(void)
This is the "block"(a term here!) and the main function where our main codes will be written. You'll see "{" on line 6 and "}" on line 11. In between {} are codes of the function.
The "int" in front means that the main function returns a "integer". (What's does that mean? You'll see Later 8) ).
There's a void in the () after main. void means "nothing", so here it means that the main function doesn't have any arguments needed or used.
cout <<"Hello World" <<endl;
cout <<"Hell PS2--- Forum XDXDXD"<< endl;
These two lines basically print the text.
cout (pronounced c-out) can be said as the device to print text on the screen. we use an "operator" (which is the "<<") and send the string of text on the right to the output device (cout in this case)
Put it another way: We put the string(characters, text) "Hello World" write to the cout device on the left.
endl simply means "end of line". (Like the "return/enter" button on our keyboard). The new string after "endl" will be printed on a new line.
When putting a string (string - characters, numbers, or text) you have to use a " at the front and end so the compiler knows that line of code is a string of text.
system("pause")
This is one of the most important functions to learn. This function tells the computer to pause the program/code until any key is hit. Why we need this?
DOS is set that when the program/code finishes running the window will automatically close. Like a small program like this the window would open and suddenly close so fast you could barely notice.
With this line added, and using this code for example, the program will pause after it pasted the "Hello World" and "Hell PS2--- Forum XDXDXD" text on so that you can see the results, and after pressing any key the program will continue and closes when it hits the end.
return 0
Remember "int main(void)"? it's sets that you need to return an integer for the function. Yup, now we're returning the main() function a 0! And hey, 0 is an integer, just what main() wants.
Basically this shows the main() that the code ends here.
It's needed at the last line of the main()! or else it's will fail when compiling.
You see a ";" at the end of each line? You can tell it's added at the end of every line of coding (the functions don't needed, because it has {} to show the area of the code.) Why do we need that?
When we compile this is how the computer reads the code:
cout <<"Hello World" <<endl;cout <<"Hell PS2--- Forum XDXDXD"<< endl;...
Everything in one line. With a semicolon the compiler knows when one line of code ends. Forgetting to put a ; can cause a LOT of trouble! Always double check before compiling.
Now Press F9 to compile. You'll need to save the source code before compiling. name anything you want, and save anywhere you like, and an .exe file will be made with the same name of the source code.
Enjoy Your First C++ program!!!