Beginners Complete Guide to C++
Here you will learn the basics of the C++ Programming language.
To start off you must know that we are using the C++ that uses the Win32 Console, not graphical interface.
Table of Contents:
1. Variable types
2. Library headers
3. input/output
Variable Types
Here is a list of the most common variable types, you will learn more as you improve, also you will learn how to use each more effectively.
int
short
long
string
char
float
double
long double
bool
each variable type takes a certain amount of memory which is listed below
ints and floats - 32-bit
short - 16-bit
chars - 8-bit
doubles and long - 64-bit
bools - 8-bit
depending on the program you may need to use one or the other, but also because computers have so much memory you could most likely just use the maximum memory usage of each type. But the problem with doing so, some people may still be running low end computers and may run out of memory.
int/short/long
int is any integer, anyone with basic math skills would know that integers are all whole numbers such as …-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5…and so on. int short and long are all used for integers only, it just depends on how much space is needed for each type. short can only hold -128 to 127. int can only hold -32,768 to 32,767, and long int -2,147,483,648 to 2,147,483,647. Also remembre that this is for most computers, though as computers advance the larger these numbers get. If you try adding a number such as 2.5 to an integer type, it will just drop the numbers after the decimal. example: 2.5 + 3 = 5
–
float/double/long double
floating point numbers(float) can be any number, from integers to floats. Then why not just use float for everything and never use integers? Floating points numbers are not that accurate, there are often times when a number lets say “3.1445″ may be the answer on one computer, but on another it may be “3.1446″, even if you say do not show decimal places, it may still use the decimal places to add the so called “integers” and you may come out with inaccurate answers. The maximum number for each type of float datatype are listed below:
float: 3.4 * 10^(-38) to 3.4 * 10^(38)
double: 1.7 * 10^(-308) to 1.7 * 10^(308)
long double: 3.4 * 10^(-4392) to 3.4 * 10^(4392)
Each set also has a number of precision after the decimal place before it starts to become inaccurate which is also listed below.
float - 7-decimal places
double - 15-decimal places
long double - 19-decimal places
–
boolean
booleans are very easy to use, all they say is True or False, if you want to do a program which checks to see if a value is correct, if it is you may say continue the program, or goto another section of the program, or in alot of cases maybe even quit program. Boolean can only hold two different values, “True” or “False”.
string/char
Chars can become very complicated, but I will just tell you the basics, you will learn how to use them alot better, and learn more functionality with it. Char is just keeps one letter in storage, so if you have a char variable and lets say you enter “Hello” to store into the char, the only thing the char will store is the “H”. Chars only take up 4-bytes.
Strings do more than char, they can store whole sentences, or more, I do not thing I have ever run into a memory limit for strings except for the computers limit. If you enter a whole sentence such as “Hello world, this is a p2l tutorial” the string will store that whole thing.
————–
Library Headers
Headers are the statements that call in a library so you may use certain functions in that library. The library that is used in almost every single program is called iostream, and to use this library you must put this at the top of your code:
#include <iostream>
This library holds all the common commands in C++ such as cin, cout, int, float, double, long int…etc. Although iostream has alot more functions that I dont know either, you can easily goto the microsoft website and look it up in their Library. Although iostream contains alot of commands you would think it would allow you to use strings, but it doesnt. To include strings into your program you need to use the library called “string”, obvious eh?
To include this file you would do the same thing, and this is the style for all libraries:
#include <string>
For your refrence this is how you call libraries
#include <libraryname>
Where libraryname is the library name. Often there are libraries that may need a “.h” at the end, you must include that in the library name for it to compile, some libraries that have the .h at the end may be exchanged and instead put the c in the front. Here is an example, the library math which includes math functions such as power, and log, and other things. But to call this you need to use this code
#include <math.h>
You may also call this library by this way also:
#include <cmath>
Although this works for this library, it may not work for all libraries, so dont hold me to this if you have to keep the .h =)
February 7th, 2008 at 3:31 am
nice sites for c++
February 19th, 2008 at 8:24 am
return is written as retrun which causes error
please correct it.
February 28th, 2008 at 2:08 pm
Thanks for notifying me of this.
July 1st, 2008 at 10:03 am
hi! can i ask if there is a kind of lesson,,that the visual c ++ has a connection w/ graphic system,,
can u help me in this topic?
introduction of c ++ to graphic system, initializing video adapter, filling area , graphic texts. , color and pallets…
pls help me reply asap.. thank you!
July 28th, 2008 at 12:02 am
world casino virtual virtual jeu casino
July 30th, 2008 at 11:43 am
thank you for this wonderful guide, you have been very helpful. I love you =D