C++ is a really good language to learn. Read this to find out how. C++ has always been one of the most used languages. It is easy to learn, but hard to learn from example. I hope this LUG can help you learn C++ the easy way.
Step 1: First program
First, open up a text editor that you can use well (VI, PICO, gedit, MS Notepad, Dev-C++ etc.) In it, type:
int main(){
return 0;
}
Save the file as program1.cpp.
cd to the directory that you saved the file in and type:
gcc program1.cpp [if there are errors, make sure you typed everything right, then type the above command again]
./a.out
./a.out should end as soon as it starts.
Now, your probably wondering what all that means.
int main(){
int: the output is an intiger (see return #
main: everything between the {} happens when the program starts
(): The parenthsis are empty because the program does not take any command line input
return 0;
return: "return" is a command. You do not need this but no good programer would leave it out.
0: 0 is the number that the program returns. It could be anynumber (under a certain limit, but too wide a limit to worry about yet). In this case, it has to be a whole number, but not always. It all depends on the intiger that we put at the start of the program
}: Ends the program (in this case).
Step 2: Hello World
Nine out of ten tutorials and books teaching C (or any other language for that matter [even VB and HTML]) will include a Hello World program. This in fact originated from C (Hello World was the first program written in C). Here is one in C/C++:
#include
int main(){
printf("Hello, World");
return 0;
}
There are two new lines now:
#include : This inserts a file into your program called stdio.h. This file comes with any real compiler, and tells the program how to do Standard Input and Output.
.h means "header".
printf("Hello, World");: This prints "Hello, World" on your screen (without the quotation marks).
; ends all commands.
Step 3: Variables
int main(){
int gg;
gg = 7493;
return 0;
}
This program should seem to do the same thing as the first one, appear to do nothing.
int gg;: makes a space in memory called gg, which can store an intiger.
gg = 7493;: sets gg to 7493
Step 4: Calling Variables
#include
int main(){
int gg gg = 7493
printf("%d", gg);
return 0;
}
printf("%d", gg);
%d: This prints gg in decimal format
gg: the first %d is gg (the first number printed [to the screen] is gg, the first [and only] variable (or number, text etc.) after the comma.
Step 5: Math
Congradulations for making it this far. I hope your having fun. Not much longer to go.
#include
int main(){
int gg;
gg = 23 + 43
printf("%d", gg);
return 0;
}
This prints out 66 [23 + 43] to the screen.
gg = 23 + 43: This adds 23 and 43 and makes gg the sum [66].
Your probably thinking "thats good but there is no multiplication or division key on the keyboard", well maybe your not, but anyway, here are the operations:
Plus: +
Minus: -
Multiplied By: * [Astrik]
Divided By: /
Step 6: "if"
#include
int main(){
int gg;
gg = 23 + 25
if (gg < 45){
printf("%d is less than 45", gg);
}
return 0;
}
Basically, anything between the inner { and the inner } is done only if gg is less than 45.
Well, thats the basics. C++ gets a lot more fun. Again, congradulations for getting this far, and good luck learning more. There are many good books on C++ , and if I were you, thats where I would start [to continue

]