how to write,compile and run C++ program on Linux

Posted: March 2, 2017 in C++
Tags: , ,

In this tutorial we will learn how to compile and run C++ program in Linux.

Now Compiling and Running  C++ Program in Linux is so easy. Just follow few simple steps and you are done.

STEP 1: First install C++ Compiler:

 

[root@localhost ~]# yum install gcc-c++

 

STEP 2: Write and save the C++ Program using any editor.

 

Here I am using VI/VIM editor to write C++ Program.

[root@localhost ~]# vim linuxprogram.cpp

 

c++ in linux

STEP3: Compile the Program.

 

[root@localhost ~]# c++ linuxprogram.cpp

 

 

STEP 4: Execute or Run the Program.

 

[root@localhost ~]# ./a.out .out
This my First Program in Linux
 [root@localhost ~]#



ANOTHER METHOD TO COMPILE AND RUN  C++ PROGRAM IS:


[root@localhost ~]# g++ linuxprogram.cpp -o linuxtiwary
[root@localhost ~]# ./linuxtiwary
This my First Program in Linux
 [root@localhost ~]#






Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s