Dev C++/C++ - Basics

All tutorials created in C++ to be posted in here.
6 posts Page 1 of 1
Contributors
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Dev C++/C++ - Basics
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 :)
You're crazy!
I'm not crazy, my mother had me tested. ~Sheldon Cooper
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Dev C++/C++ - Basics
MrAksel
This was amazing, i have searched for that basics of C++ for a long time but in only find more advanced tuts
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Re: Dev C++/C++ - Basics
Agust1337
Thank you, I'm glad you liked it :)
You're crazy!
I'm not crazy, my mother had me tested. ~Sheldon Cooper
User avatar
Trippy
Just Registered
Just Registered
Posts: 3
Joined: Wed Jun 08, 2011 4:04 am

Re: Dev C++/C++ - Basics
Trippy
Nice Post Keep Up The Good Work :)
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: Dev C++/C++ - Basics
benji_19994
really time wasting!!
User avatar
DeveloperJacob
VIP - Donator
VIP - Donator
Posts: 87
Joined: Sun May 27, 2012 12:40 pm

Re: Dev C++/C++ - Basics
DeveloperJacob
benji_19994 wrote:
really time wasting!!
Your post is time wasting. This is very well explained and very usefull :D
Image
6 posts Page 1 of 1
Return to “C++ Tutorials”