Page 1 of 1

Dev C++/C++ - Basics

Posted: Wed Mar 16, 2011 2:43 pm
by Agust1337
Hello and greetings everyone, in this thread I will be showing the basics in C++ while getting started.
I used Dev C++ for this tutorial.
Click here to download Dev C++

the basic hello world:
Code: Select all
//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;

int main() //This is the start of the program(like Public Form1(); in C#)
{
    cout<< "Hello world!" <<endl; //outputs the text
    system("PAUSE"); //Tell's the program to paus
    return(0); //Ends the programs code
}
NOTE: \n sign is a line break.

Cin and Integers and how they can be used:
Code: Select all
//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;

int main() //This is the start of the program(like Public Form1(); in C#)
{
    int num = 0; //This is an declared integer. It is important to  keep the number at 0,
    //as  we ask the user to change it later in the program.
    cout << "Please input a number:\n";
    cin >> num; //This line is our input, where the user enters a number. Notice how the
    //arrows are pointing right not left, as the output would.
    cout << "The number is";
    cout << num;
    cout << "\n";
    system("PAUSE");
    return 0;
}
Using doubles:
Code: Select all
//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;

int main() //This is the start of the program(like Public Form1(); in C#)
{
    double dnum = 0.0; //This has the same principals as the integer BUT
    //it only deals with decimals where as integers deal with whole numbers.
    //Note: Always remember to put the letter 'd' before your declared double code.
    //For example:
          //dnum
    //This is so that in your code when you use that double it knows exactly that 
    //this is a double. 
    cout << "Please enter a decimal number:\n";
    cin >> dnum;
    cout << "The number is";
    cout << dnum;
    cout << "\n";
    system("PAUSE");
    return 0;
}
If and Else statements:
Code: Select all
//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;

int main() //This is the start of the program(like Public Form1(); in C#)
{
    int num = 96;
    if(num == 96){
           cout << "Hello\n";
           }
    else{
         cout <<"World";
         }
    system("PAUSE");
    return 0;
}
Explained:
Code: Select all
if (true){
     //Execute these statements if TRUE
}
else{
     //Execute these statements if FALSE     
}

Thanks for viewing my tutorial :)

Re: Dev C++/C++ - Basics

Posted: Wed Mar 16, 2011 2:50 pm
by MrAksel
This was amazing, i have searched for that basics of C++ for a long time but in only find more advanced tuts

Re: Dev C++/C++ - Basics

Posted: Wed Mar 16, 2011 2:52 pm
by Agust1337
Thank you, I'm glad you liked it :)

Re: Dev C++/C++ - Basics

Posted: Fri Dec 09, 2011 3:14 pm
by Trippy
Nice Post Keep Up The Good Work :)

Re: Dev C++/C++ - Basics

Posted: Tue Sep 18, 2012 8:12 am
by benji_19994
really time wasting!!

Re: Dev C++/C++ - Basics

Posted: Tue Sep 18, 2012 8:38 am
by DeveloperJacob
benji_19994 wrote:
really time wasting!!
Your post is time wasting. This is very well explained and very usefull :D