C++ is an extreme language and the one of the most difficult. C++ like PHP derives from C so C functions can be called when programming in C++. I will tell about the very basics to get started into the C++ programming world.
Below you see the very least for a C++ console program just to run and be empty. I have commented on the main points.
#include //contains basic input and output functions like cerr, clog, cout, and cin and basic operators
#include //contains other basic functions and operators
//more headers are available in Dev-CPP’s include directory. These include math.h (C header) for math functions sin, cos, tan, sqrt, fstream sometimes fstream.h (compiler dependent) that contains functions for reading and writing files in C++ (will explain later), and one that is very useful string.h sometimes string (again compiler dependent) which contains string manipulation functions such as erase and replace.using namespace std;//this means that you want to use the namespace std which contains basic input and output functions otherwise you would have to call functions, operators, etc in a manner of namespace::functionname like std::cout
int main(int argc, char *argv[])//main function in console program where everything goes that needs to be done. This is a custom function and can also be seen as taking no arguments, int main()
{
system(“PAUSE”);//the system function. Whatever you put between the quotes is what you want to be sent to the command line. In this case PAUSE tells the program to wait and let the user see the results
return 0;//return value of 0 because the function is an int
}
Now that the structure of a basic console program has been explained now variables. First, what is a variable? A variable is sort of like a variable in math. Variables hold values and can be outputted. These variables can consist of letters, numbers and some symbols. Variables can not have the same name as another variable in C++. For example the first set of code outputs an error on compilation and the second compiles with no errors. Note: The code takes into consideration that the variables are declared in the main functions in the above template.
int i;
i = 0;
char i;//variable already used and declared as variable type int
i = ‘a’;//variable is type int and cannot hold a character
int i;//perfect
i = 0;//perfect
char a;//perfect
a = ‘a’;//perfect
Now for the variable types. A variable type decides what that variable can hold. A type of int can only hold whole numbers for example -1, 0, 1, etc. A type of char can only hold a single character or symbol (unless character array, or pointer). A type of string can hold letters, numbers, and symbols. A type of float can hold a single precision value (decimal, fraction) accurate to 7 decimal places. A type of double can hold double precision values (decimals, fractions) accurate to 15 decimal places.
I have given enough information to write a very simple program. Good Luck.
Print This Post
Email This Post
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| By N2H | |||||
Comments RSS
TrackBack Identifier URI
You must be logged in to post a comment.