+  Freddy1990.com
|-+  Programming» C++ Programming» [C++][Tut] Getting started with C++!
Username:
Password:
Pages: [1]
  Print  
Author Topic: [C++][Tut] Getting started with C++!  (Read 1457 times)
Nitrus
Newbie
*

Rep: 0
Offline Offline

Posts: 47


View Profile Email
« on: March 09, 2007, 09:25:50 PM »

This will be split in to 3 sections. The compiler, The knowledge, and The code. This is so you will take an effective step in to learning C++.

The Compiler
There are many many many C, C++, and other C based language compilers spread around the internet today. Two of the most common are Microsoft's Visual C++ (For use with Windows), and the GNU C++ Compiler(commonly known as gcc, mostly for use with *nix). If you do not like your compiler, then you most likely won't like the language, hence there would be no point learning in the first place! So lets get comfortable with compilers before we learn the language itself.

Windows Compilers
The most common Windows compilers are MS Visual C++ 6 through to 2005, Borland's C++ Builder, and Bloodshed's C++ Compiler. There are very many more compilers out there, but I'll cover the most used ones from hereon in, as they generally seem to fit most people.

Visual C++ is a great IDE for C++. It comes with all versions of Microsoft Visual Studio. The most commonly used C++ compiler in the series is Visual C++ 6.0. One reason may be that it uses standard C++ rather than a Visual Interface, allowing easy code conversion to another OS (well, console at least Wink). Another may be that people just seem to like Visual Studio 6.0, it was probably at the height of its existence a few years ago, however.

Next we have Borland's C++ Builder. C++ Builder is a very easy to use compiler, it provides an easy interface, while holding the power of C++ that we all love. Although this is a great compiler, and deserves two thumbs up from me, I like the alternatives, myself. This choice is up to you, however.

Last but not least, we have BloodShed Dev-C++. Dev-C++ is probably one of the best free C++ compilers available for download today. It was made in Delphi, and has a very easy interface. It should mostly be used for learning and novelty development rather than a pro setup. Most professional C++ users should look at Buying or Pirating a commercial product. You can download Dev-C++ from http://www.bloodshed.net/ - (I use Dev-C++).

Linux Compilers

The GCC (GNU C++ Compiler) is a command line tool used to compile C++. It may seem intimidating to use at first, after all, it is a program in the Linux command line, but it really is quite easy once you get the hang of things. Two thumbs up from me.

You can post and add to the list of compilers if you want.


The Knowledge

With C++, you can't just expect to get in there and start coding, it takes time. Any of you with experience in the C, C#, or Java languages should find it easier to learn than that of a person with knowledge of VB. C++ takes time to learn, therefore, it will take time for you to program in it. many people will say that C++ is hard. In fact, C++ is hard, but with effective coding techniques and crucial skills put in motion, C++ will become all but a difficult task. C++ was made as a superset of a language called C, which evolved from a language called B, which evolved from a language called BCPL.

C was a very very successful language, it has been the base of programming for a long long time. C++ is a superset of C, with added features, coding structure, and full object orientation. C++ can be effectively coded with C along side it, therefore it is useful to know both languages to be a professional coder.

From C++, two new languages evolved. C#, and Java. Java is versatile, making it very good for use on the internet. C# I find is like a mix between Java and C, so anyone who knows C or Java would find it wise to learn C# before learning the opposite language. C++ is still a big-daddy in programming today, even though it is old - so don't doubt its power!

With this power comes flexibility and the ability to do almost anything to your computer (virtually, not physically XD). All you need to do is press the right buttons. So to say, you can even make your own operating system like Windows, Mac or Linux with a language such as C or C++. Unfortunately, this is not so with Java or C#, because these two languages must be interpreted.

What is the difference between interpreted and compiled?

Interpreted means the program must be "read" from the operating system via the binaries that have been installed to use the language. I.E. Java and Flash. the Java Runtime Environment is required to run Java applications, just like it is for Macromedia Flash player to run Flash applications. C++, C, and other lower level languages are compiled, meaning they can be directly executed by the OS itself.

Okay, so whats better for me?

It all depends on what you're looking for. Myself, I'm a mix between VB, Java, C++, and C#. VB, Java, and C# are interpreted, but they are still effective programming languages for the OS that can run them. C++ is compiled, meaning it can make fast executing applications run directly from the OS. Neither should be considered a "better" language, because they all do what they were made to do, and thats all that they should be used for.

A good chain of languages to learn would probably be something like this:
Delphi->Java->C#->C->C++->HTML and PHP
This may seem a bit ambitious, but its a good mix. Delphi is a RAD useful for fast applications. Java is great for versatility. C# is a powerful language for use with Windows. C and C++ are great languages for use with almost all OS's. and HTML and PHP are Web languages used to make things such as websites, and without a knowledge of these you would probably soon find yourself in the dark.


The Code
Coding is the hardest part about this, as is always. People will say that C++ sucks for making GUI's, when infact, that is not so, It just requires a lot more time and effort to make a good GUI.

For this purpose, we will be making a Console application to be ran through Command line. command line applications are generally the easiest to learn first, which is why I will not be taking you through GUI development in this tutorial. I haven't even grasped GUI's myself, so you will most likely NEVER get a GUI tutorial out of me.

copy this code down in to your compiler:
Code (C++):
#include <iostream>
using namespace std;
 
int main()
{
 
  // This is a comment, it will let the author remark on his code.
 
  cout << "Hello world!\n";  // This is a statement, therefore must be issued with a semicolon at the end of the line
  // The above can just as easily be written as:
  // cout << "Hello world!" << endl;
  // but instead we used "\n" at the end of HelloWorld, which does the same thing!
 
  return 0; // Seeing as main() is a function, we must return a value. In this case, 0 means it has executed properly.
}

compile your project. Windows uses will need to open an instance of CMD to execute this, otherwise it will just close the prompt window before you can blink. Linux users can execute their output using something like this:
Code (C++):
./a.out
depending on the output file.

Now you will see that it outputs "Hello World" Followed by a new line. Remove the "\n" from the end of "Hello World" and see what happens Wink

Now, go through it line by line.

Code (C++):
#include <iostream>
using namespace std;

This part of the code is the most vital for your programs execution. It is the part of the code that is preprocessed before anything else happens. the cout function and everything else vital to creating a console application is inside the "iostream" header.

#include <iostream> simply includes the <iostream> header, which as stated, contains all of the vital functions. using namespace std; means it is using a namespace called std, which is also as vital for program execution. Think of a namespace as a placeholder for execution.

Code (C++):
int main()
{
  ...
  ...
}

This is the main function. After the preprocessed piece of code, this is the first part of the program that executes, therefore main() MUST and I mean MUST be a part of every single C++ program.

Code (C++):
cout << "Hello World!\n";

This outputs the line "Hello World!" as well as a new line. Read the comment below the bit of code for more information.

Code (C++):
return 0;
as the comment says, seeing as main() is a function, it must return a value. returning 0 generally means it has executed properly.

C++ is case sensitive, therefore it was made so that almost everything that is written in C++ apart from variables, strings, and comments is in lower case, to avoid confusion.




THE END

What do you think?
« Last Edit: June 24, 2008, 01:41:42 PM by Freddy1990 » Logged
Zoiked
Full Member
***

Rep: 0
Offline Offline

United States United States

Posts: 125

What happens if I put text here. :P

Bllizzd@gmail.com
View Profile WWW
« Reply #1 on: April 08, 2007, 12:27:50 AM »

Great Tutorial but there is one thing I disagree with......
Quote
Delphi->Java->C#->C->C++->HTML and PHP

I Think this is a bad learning line because the the fact that this is a very broad range of languages for one person to learn.

Also, Html should be first because of its simpleness and its fun to learn. Next (Sadly) Visual Basic should be next to introduce the programmer into OOP in a simplified language. Next should either be Delphi(I Think Its Outdated!) or C# or just skip to C++ or Java(C++ Would be better though).

Html->Visual Basic(6 or .NET)->C#(Just Basics)->C++
Logged
sparkz
Leecher


Rep: 0
Offline Offline

Posts: 3


View Profile
« Reply #2 on: April 16, 2007, 12:29:26 PM »

Very nice, just got a few nit-picks.

Dev-C++ is an IDE that uses Mingw compiler - it is not a compiler itself.
int main() must return an integer value, not just any random value.

Other than that - great job (Y)
Logged
Se7eN
Global Moderator
*****

Rep: 2
Offline Offline

United States United States

Posts: 458


Cpp Guru


View Profile Email
« Reply #3 on: May 10, 2007, 07:37:24 PM »

Great Tutorial but there is one thing I disagree with......
Quote
Delphi->Java->C#->C->C++->HTML and PHP

I Think this is a bad learning line because the the fact that this is a very broad range of languages for one person to learn.

i agree expecally since c is the only one on the list that does not fully support oop (besides html and php...their web languages so they don't count Tongue)

Also, Html should be first because of its simpleness and its fun to learn. Next (Sadly) Visual Basic should be next to introduce the programmer into OOP in a simplified language. Next should either be Delphi(I Think Its Outdated!) or C# or just skip to C++ or Java(C++ Would be better though).

Html->Visual Basic(6 or .NET)->C#(Just Basics)->C++
Logged

Quote from: TheGuyWhoGotOn
Ok you look like you're going to break a lot of rules so here is a heads up, next time if you try to log in and cant, its because your banned.
WhoCares357
Wiki Writer
Donator
*****

Rep: 0
Offline Offline

United States United States

Posts: 37

Donated $9.07


Freddy Follower


View Profile Email
« Reply #4 on: June 05, 2007, 11:04:50 AM »

What's the difference between c++ and c#?
Logged

to accept all is to accept nothing
pplsuqbawlz
Community Member
******

Rep: 3
Offline Offline

United States United States

Posts: 12


View Profile
« Reply #5 on: June 16, 2007, 08:07:54 AM »

SEE: http://www.tiobe.com/tpci.htm - JAVA/C/C++ etc.
Logged
disturbedone2004
Leecher


Rep: 0
Offline Offline

United States United States

Posts: 2

Comp Sci Major Senior Lvl

Disturbedone2004
View Profile
« Reply #6 on: September 28, 2007, 07:05:13 PM »

I feel I should mention that while /n and endl both end the current line and begin a new one, endl flushes the memory buffer when used. I always use endl.
Logged

There are 10 kinds of ppl in this world

those who understand binary,

and those who don't.
Freddy1990
Administrator
Extreme Donator
*****

Rep: 19
Offline Offline

Belgium Belgium

Posts: 2254

Donated $50


freddy1990@gmail.com Freddy199O
View Profile Email
« Reply #7 on: December 12, 2007, 12:52:46 PM »

Quote
Delphi->Java->C#->C->C++->HTML and PHP
That's bs...
First of all, html isn't a programming language, it's a markup language, that's 2 completely different things...
And if you want to learn java you shouldn't waste ur time learning Delphi, c++ or any other native language because java works very differently...
For that matter it's better to start with the language you want to learn rather than to learn another one before that which you won't use...
Logged
darak555
Leecher


Rep: 0
Offline Offline

United States United States

Posts: 9


View Profile Email
« Reply #8 on: June 15, 2009, 03:44:02 PM »

i have basic C# C++ J# and web developer
Logged
BroB0t
Newbie
*

Rep: 0
Offline Offline

United States United States

Posts: 10


View Profile Email
« Reply #9 on: July 06, 2009, 04:53:21 PM »

Nice tut helped me out.
Logged
Freddy1990.com
   

 Logged
Pages: [1]
  Print  
 
Jump to: