wizeman
Banned
- Messages
- 256
- Reaction score
- 0
- Points
- 0
This is the starter to a series of C++ tutorials I will write when I have the time (mainly during my third period class ). Anyways, this tutorial asssumes you have no background experience in programming (its fine if you do), and may teach a lazy habit or two. Note that I do not have access to a compiler as of writing this, and there may be a glitch or two in the code (Please let me know if you find one).
First off, I will explain the basics:
A compiler is a program that turns your code into a working executable. Some common compilers are gcc and g++.
An IDE (integrated development environment) is exactly what it says - an environment for developing code in. There are many different IDE's available, such as Dev-cpp, Borland, and Visual C++. I recommend Dev-cpp, because it is easy to use, as well as being free. The link is as follows: http://www.bloodshed.net/dev/devcpp.html
All instructions in this tutorial assume that you have Dev-cpp installed.
To compile your code in Dev-cpp, go to Execute - compile. If you want to immediately run your program after compiling, select Execute - Compile and run.
Lets continue by jumping straight into some code for the easiest possible program; Don't worry if you do not understand it, I will explain afterwords what it all does.
OUTPUT:
Hello World! Press any key to continue.
EXPLINATION:
#include - This includes a file, in this case iostream, which defines many common functions for a C++ program (such as cout, endl, etc.) Notice that we have:
#include <iostream>
The < and > signify that it will look in the include directory, which will vary depending on what compiler you use. In this case it is [wherever you install dev-cpp]\include .
int main() Is the entry point, or starting point of your program. This is where all code execution begins.
{ - This is an opening bracket. For now, just realize that int main needs one immediately after it.
cout << - cout, or console out, is used for outputting text to the screen in a console program. For example, If I put:
It would output Hello World! to the screen.
system("PAUSE") - This executes a command prompt command in your program, and is usually not use in programs. For the sake of simplicity, I used it here, I will provide an alternitive for it later. You can put any command prompt command within the quotes, and it will execute it. system() is a function (something you can call).
return 0; - this lets windows know what happened to your program. Typically, if you return a non-zero value the program failed, otherwise it suceeded.
} - This signifies the end to int main(). For now, just realize you need it.
Notice that every line ends with a semicolon. In C++, this signifies the end of a line of code...well, thats not really correct, because whitespace is ignored in C++ ( you can have it span as many lines as you want, or put as many spaces as you want). Well, Im out of time ,I will post a follow-up to this later when I get home.
[/code]
First off, I will explain the basics:
A compiler is a program that turns your code into a working executable. Some common compilers are gcc and g++.
An IDE (integrated development environment) is exactly what it says - an environment for developing code in. There are many different IDE's available, such as Dev-cpp, Borland, and Visual C++. I recommend Dev-cpp, because it is easy to use, as well as being free. The link is as follows: http://www.bloodshed.net/dev/devcpp.html
All instructions in this tutorial assume that you have Dev-cpp installed.
To compile your code in Dev-cpp, go to Execute - compile. If you want to immediately run your program after compiling, select Execute - Compile and run.
Lets continue by jumping straight into some code for the easiest possible program; Don't worry if you do not understand it, I will explain afterwords what it all does.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World! ";
system("PAUSE");
return 0;
}
OUTPUT:
Hello World! Press any key to continue.
EXPLINATION:
#include - This includes a file, in this case iostream, which defines many common functions for a C++ program (such as cout, endl, etc.) Notice that we have:
#include <iostream>
The < and > signify that it will look in the include directory, which will vary depending on what compiler you use. In this case it is [wherever you install dev-cpp]\include .
int main() Is the entry point, or starting point of your program. This is where all code execution begins.
{ - This is an opening bracket. For now, just realize that int main needs one immediately after it.
cout << - cout, or console out, is used for outputting text to the screen in a console program. For example, If I put:
Code:
cout << "Hello World!";
It would output Hello World! to the screen.
system("PAUSE") - This executes a command prompt command in your program, and is usually not use in programs. For the sake of simplicity, I used it here, I will provide an alternitive for it later. You can put any command prompt command within the quotes, and it will execute it. system() is a function (something you can call).
return 0; - this lets windows know what happened to your program. Typically, if you return a non-zero value the program failed, otherwise it suceeded.
} - This signifies the end to int main(). For now, just realize you need it.
Notice that every line ends with a semicolon. In C++, this signifies the end of a line of code...well, thats not really correct, because whitespace is ignored in C++ ( you can have it span as many lines as you want, or put as many spaces as you want). Well, Im out of time ,I will post a follow-up to this later when I get home.
[/code]