Starting out
Before you can start programming in C++ it is a good idea to get a compiler that works well. I recommend getting Visual C++ 2008 express edition, as it is free and fairly powerful, but there are a number of compilers out there.
Basic C++ applications start out like so:
int main(){
return EXIT_SUCCESS;
}
Using Comments in Code
Comments in C++ can consist of either a single line comment: // comment here, or a block comment: /* Comment here
and here
and here */
In source code comments can look like so:
int main(){ // create the main function
return EXIT_SUCCESS; // exit saying that the program ran successfully
}
If you wanted to use block comments instead that can look like so:
/* This function attempts to return
an integer upon successful completion
*/
int main(){
return EXIT_SUCCESS;
}
However, people normally format their block comments like so:
/* This function attempts to return
*an integer upon successful completion
*/
int main(){
return EXIT_SUCCESS;
}
To avoid confusion.
NOTICE - There is an additional * and space in each line to make the comment block line up correctly.
Data Types
There are a number of "primitive data types" in C++ that consist of int, double, float, long, char, bool, and others. These are known as "primitives" because they don't require that you import anything into your code to use them successfully.
There are also more complex data types, like String, or Student (we will create a simple class for this in a second). The complex data types need to be initialized to work correctly.
Here is a simple example of a student class:
class Student{
private:
char* name;
public:
Student(char* nName){
name = nName;
}
char* getName(void){
return name;
}
};
Which can be implemented like so:
Student* test = new Student("Freddy");
printf("The Student %s\n", test->getName());
return 0;
The end
I know this isn't the best tutorial, but I hope it shows some of the basics behind C++.






MultiQuote








|