top of page

         How to Compile and Run a C++ Program on Ubuntu Linux

 

              Step 1: Open up a terminal

                                         Search for the terminal application in the Dash tool (located as the topmost item in the Launcher).                                                               Open up a terminal by clicking on the icon.

                                       

                                        For ease of future access to the terminal application, right click its icon in the Launcher and                                                                               select “Lock to Launcher”.

 

                           Step 2. Use a text editor to create the C++ source code 

                                         Type the command

                                                       gedit hello.cpp

 

                                         Enter the Cpp source code below:

 

                                        #include<iostream>

                                        using namespace std

                                        main()

                                          {

                                             cout<<"Hello World\n";

                                          }

 

                                         Close the editor window.

 

                             Step 3. Compile the program

                                          Type the command

                                                  g++   hello.cpp

 

                           Step 4. Execute the program 

                                         Type the command

                                            ./a.out 

 

                                         This should result in the output Hello World

 

 

 

 

 

 

 

 

 

 

 

bottom of page