Advertising (This ad goes away for registered users. You can Login or Register)

Learning Programming With C++

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Locked
SHA-1
Posts: 26
Joined: Sat Jun 09, 2012 9:20 am
Location: In my house...

Learning Programming With C++

Post by SHA-1 »

<<Prev | Next>>

Index

1.Intro, Setup and Tools
2.Underneath The Hood
3.Understanding Our First Program

Introduction

C++ is a programming language used to create high-end applications.
Used by almost all games,(If not all!) C++ is a fine language to learn, especially if you want to become a game developer.

C++ is based on C, but instead of just using functional and procedural programming, it also OOP (Object Orientated Programming).

So in C++ you can program in 3 different paradigms, OOP, procedural and functional.

So if you if your coming over from the programming language C, you'll find this tutorial even easier!!! ;)

*Note: In these tutorials, I will be using a standard POSIX (i.e Linux),
This code should work with Windows but for any specific problems with that Platform, I can't help, Sorry!!!


**Note: I will be using Ubuntu 12.04 for these tutorials

Install the software that is required

Linux:

We use 2 things to make our programs: Our Compiler and a Text Editor.
The text editor I will be using is Gedit as its the default text editor on Gnome and it supports syntax highlighting.

The compiler g++ does come by default on most distros, so we need to do a couple of commands in the terminal:

Code: Select all

sudo apt-get install build-essential
Now, see if g++ was installed typing in the terminal:

Code: Select all

g++
if it gives an error, then type into the terminal:

Code: Select all

sudo apt-get install g++
Now, type into the terminal:

Code: Select all

g++
To invoke g++.

***Note: You can set up an IDE (Intergrated Development Enviroment) but its a good learning experience to compile with the terminal. Although if you really want to set up a IDE, I recommend Eclipse.

Windows:

Setting up a compiler in windows is as easy as pie.
Just install an IDE (Intergrated Development Enviroment), I recommend Eclipse.

Checking our Enviroment

Now open your text editor and type this in:

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    cout<<"Hello World!!!"<<endl;
    return 0;
}
****Note for windows users: Some programs (for example, this one), might flash onto the screen and you will never have a chance to see it, so you need to add a "cin.get();", at the end of the program, if there is a need for cin.get(); I will notify you with a sentence saying so.

Now save it as foo.cppand go onto the terminal.

Now compile it with the command:

Code: Select all

g++ foo.cpp -o foo
now run it a you have a sweet looking C++ program.

Now that was that so hard? ;)

See you on the other side. 8-)

<<Prev | Next>>
Advertising
Last edited by SHA-1 on Wed Aug 15, 2012 10:42 am, edited 3 times in total.
Languages, I know:
C++, C, Perl, Bash.

Languages I'm learning:
Assembly, Python, Java.
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Learning Programming With C++

Post by m0skit0 »

Just a remark: C++ is multiparadigm. It is not only OOP but has elements of procedural and functional as well. And Eclipse works in Linux as well ;)
Advertising
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Learning Programming With C++

Post by Acid_Snake »

Nice Tuto. This should be stickied.
SHA-1
Posts: 26
Joined: Sat Jun 09, 2012 9:20 am
Location: In my house...

Re: Learning Programming With C++

Post by SHA-1 »

m0skit0 wrote:Just a remark: C++ is multiparadigm. It is not only OOP but has elements of procedural and functional as well. And Eclipse works in Linux as well ;)
Yeah, forgot about that, will edit though.

But you will have to wait until tomorrow as I dont have access to a computer right now and Im on my psp browser to post this.

BTW I think it's best to teach people to use the terminal and compile that way, other then using a IDE.

-----
my psp browser , now my tut is cut in half :cry:

but dont dispair, I kept a copy and it will up and running by tomorrow

Update: The tut is up and running and this time I won't let my psp touch it :D
Last edited by SHA-1 on Tue Aug 14, 2012 10:23 am, edited 2 times in total.
Languages, I know:
C++, C, Perl, Bash.

Languages I'm learning:
Assembly, Python, Java.
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Learning Programming With C++

Post by m0skit0 »

SHA-1 wrote:BTW I think it's best to teach people to use the terminal and compile that way, other then using a IDE.
Ok, but then for all OS, not just for Linux ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
SHA-1
Posts: 26
Joined: Sat Jun 09, 2012 9:20 am
Location: In my house...

Re: Learning Programming With C++

Post by SHA-1 »

m0skit0 wrote:
SHA-1 wrote:BTW I think it's best to teach people to use the terminal and compile that way, other then using a IDE.
Ok, but then for all OS, not just for Linux ;)
True.
It is good if they learn to compile with the terminal on all OS's as there extra tricks that can really be life saving.
Like using the -s switch to stop the compiler after it generates assembly as you can do some tweaks to the code and make it MUCH faster.
Acid_Snake wrote:Nice Tuto. This should be stickied.
Thanks Acid_Snake, so do I! :D
m0skit0 do you think this should be sticked? :?:
Languages, I know:
C++, C, Perl, Bash.

Languages I'm learning:
Assembly, Python, Java.
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Learning Programming With C++

Post by m0skit0 »

SHA-1 wrote:after it generates assembly as you can do some tweaks to the code and make it MUCH faster
Really you should NOT mess with compiler generated assembly. And on a general basis, compiler will produce MUCH MORE optimized code than you will, specially C/C++ compilers, be sure about that. But for this you have to tell the compiler to optimize (i.e. gcc's -O switch)
SHA-1 wrote:m0skit0 do you think this should be sticked? :?:
Why not, once you really start with C++ programming :mrgreen: ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
SHA-1
Posts: 26
Joined: Sat Jun 09, 2012 9:20 am
Location: In my house...

Re: Learning Programming With C++

Post by SHA-1 »

m0skit0 wrote:
SHA-1 wrote:after it generates assembly as you can do some tweaks to the code and make it MUCH faster
Really you should NOT mess with compiler generated assembly. And on a general basis, compiler will produce MUCH MORE optimized code than you will, specially C/C++ compilers, be sure about that. But for this you have to tell the compiler to optimize (i.e. gcc's -O switch)
SHA-1 wrote:m0skit0 do you think this should be sticked? :?:
Why not, once you really start with C++ programming :mrgreen: ;)
I'm writing the 3rd part of the tut right now.

UPDATE: The 3rd part is now online!!! :D
Languages, I know:
C++, C, Perl, Bash.

Languages I'm learning:
Assembly, Python, Java.
Locked

Return to “Programming and Security”