I have to do a program for my C++ class, and we have to write all programs using gedit on ubuntu and run them all using the terminal command prompt. I dont know what the whole ./a.out is, and all i have for my program is

// This program will calculate an employee's total annual pay.
#include <iostream>
using namespace std;

int main ()
	double payAmount, payPeriods,annualPay;

	payPeriods = 26;
	payAmount = 1700.0;
	annualPay = payPeriods * payAmount
	cout << "Employees annual pay is $" << annualPay<< ".\n"	
	return 0;

how do i run it?

Edited by Nick Evan: Added code-tags

6 Years
Discussion Span
Last Post by VernonDozier

a.out is the executable program's name when you don't specify a program name. You can't run an uncompiled C++ program. You can only run something that has been compiled into machine code. You compile with the g++ command.

You start with a C++ program like you have done. Let's say the name of it is my_program.cpp. Let's say you want the compiled program to be my_executable.

You can edit it in gedit. Then at the cmmand line, type this:

g++ my_program.cpp -o my_executable

Type the "ls -l" command at the prompt and you should now see a new file called "my_executable". Note that it will be flagged as executable (i.e. there will be an "x" next to the filename. Note the lack of an "x" next to "my_program.cpp". To run it, type this:


The ./ means "run this program". What follows is the name of the program. If you type this:

g++ my_progam.cpp

the executable will be named a.out and you'll do this:

Well explained
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.