C++ Lesson 3 – Setting the background PROGRAMMING for LINUX.

C++ official tutorials by SecDevil.com
C++ official tutorials by SecDevil.com

If you work with Linux, your distribution probably included a C++ compiler. Often the C++ compiler in Linux is g++. It is a compiler in the GNU compilers collection.

If you are a beginner to C ++, please read our previous lessons.

C++ full tutorial | How to start C++ | Part 001

C++ Lesson 2: Setting the PROGRAMMING Background for WINDOWS

Installing g++

First we need to see if the g++ compiler included in the computer, open the terminal and type g++ and press Enter. If you show a line like this, the g++ compiler is already installed on the computer.

g++: fatal error: no input files

compilation terminated.

If you show a line like this.

command not found

So you need to install the g ++ compiler. When installing the g ++ compiler on Linux, it may change based on your Linux distribution. For example, if your computer is Ubuntu Linux, you can type the compiler and install it.

aptitude install g++

If you have another Linux distribution on your computer, you need to install the g ++ compiler for that distribution. You can easily find it through Google.

g++ Running the computer.

g ++ is very easy to use, so first we need to create a small file. You can use any text editor on your computer to do it. I am using a gedit text editor.

#include <iostream>

int main ()
{
std::cout << “Hello, world” << std::endl;
}

First write the lines at the top of your text editor. (In particular, you should not copy the source code that I give you in these lessons to your text editor. If you learn programming, we need to develop our typing skills from scratch.) Then you have to save your source code as ‘hello.cpp’ and give the file extension as ‘.cpp’.

Now open a terminal window and go to the folder where you saved the file. Then type:

g++ hello.cpp -o hello

Now hit enter.

The -o option gives the output file a name. If you simply use “g ++ hello.cpp” instead of using that option, the output file will be saved as β€˜hello.cpp’.

Running your program

Now let’s see how we can run the program we run. The name we have given to the program is hello, you can easily type this and run the program.

./hello

Now you need this type of output.

Hello, world Okay, now that we’ve set up the programming environment for Linux. If you want to use the code::Blocks IDE program, you can install this program in future lessons. Or you can easily create a program like the one above. If you are installing Code::Blocks, install the ‘Code::Blocks’ after installing the ‘g ++ compiler’. Ubuntu Software Center has the ‘Code::Blocks’ IDE.

Ubuntu Software center – click here

C++ full lesson in sinhala language. you can read full post.

Leave a Reply

Your email address will not be published. Required fields are marked *