Featured Streamer:

A Brief Look at C++ - Part 1

A Brief Look at C++

Brief Part 1:
First off this is not a guide for complete beginners, this brief is for those who have done programming before and want to adapt to using C++ or renew their understanding.

With C++, Compilers are more important than with C# and Java, this is due to C++ having a couple different standards. In this brief and any following briefs, the standard which will be used is the ANSI C++ standard which will work with any ANSI-Compliant C++ compilers for Windows, Mac, UNIX, Linux and so on.

If you have worked with C++ before you’ll note that the use of library "includes" change from the pre-ANSI standard which requires the developer to place a .h (“header” file extension) to the name of the included library. 

However, be aware that not all compilers are consistent in their support for #includes that omit the file extension “.h” if you run into error messages you may need to add the extension.

Pre-ANSI Style: #include <iostream.h>
ANSI Style: #include <iostream>

Note that pre-ANSI standards also do not require the developer to place std:: in front of cout and cin. 
pre-ANSI Style:
cout << “Hello World\n”;

ANSI Style:
std::cout << “Hello World\n”;

We’ll discuss the meaning for std::cout and std::cin in brief part 2.

Since we will be going to be using the inbuilt editors usually for the game engine or visual studio, the need to download standalone compilers is not required. However, if the need ever comes it is good to know the following tip.

When writing code that is to be compiled, do not use a word processor, instead use a basic text editor like GEdit, Kate, Leafpad, Mousepad, Pluma, Nano, Vim or Notepad++ for Linux. Notepad, GEdit or Notepad++ for Windows or GEdit, Notepad++ and TextEdit for Mac. 

The reason for this is because word processors include special formatting within the file which will cause errors in the compiler, we don’t see this additional formatting while using a word processor but if opened with an XML editor or Notepad++ (a very versatile Text editor which I highly suggest using on any OS if you can), you will be able to see the added formatting code.

Open up your IDE or text editor and write this into the text area.
Example Program:

1: #include <iostream>
3: int main()
4: {
5: std::cout << “Hello World\n”;
6: return 0;
7: }

If you receive an error that there is no prototype for “main” while compiling (This is due to one of those pesky compiler variations), just add the line

int main();
before line 3.

Please remember not to include the numbers on each line i.e. 
Yes - #include <iostream>
No - 1: #include <iostream>

We’ll cover this more in part 2, for now, this is the end of brief 1.


Most Popular

Scalecaller Peak Dungeon Tips (Normal) - Elder Scrolls Online (Second Boss)

Scalecaller Peak Dungeon Tips (Normal) - Elder Scrolls Online