Setting Up Your C++ Environment

This is a part of the series of posts which form a basic guide for programming in C++ under Debian based Linux

So, you have finally decided to learn C++ and start your journey to becoming a programmer. Except, you don’t know how to start.

To begin, you will require the ability to compile and run all the code you will be writing. For this we will use the GCC compiler for C++. Fire up your terminal and grab it from apt :

$sudo apt-get update
$sudo apt-get install g++

I like all of my C++ programs to sit in one place. We make a nice directory for that.

$cd ~/
$mkdir c++

Now, we are finally going to write and compile our first program: the Hello,World!

Fire up your favorite text editor and type in the following code for Hello World:

#include<iostream>

using namespace std;

int main()
{
        cout<<"Hello,World!\n";
        return 0;
}

Save the file as “hello.cpp” in your c++ folder.

To compile and run the program, fire up your terminal :

$cd ~/c++
$g++ -Wall -Werror hello.cpp -o hello.exe
$./hello.exe

Congratulations! You have just run your first piece of code! The gods of programming will be pleased.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.


%d bloggers like this: