// A first C++ program that sums two numbers. #include <iostream> using namespace std; int main() { int x, y, sum; y = 5; x = 6; sum = x + y; cout << "The sum is " << sum << endl; return 0; } // main
The sum is 11
cs-class-1% <--- the command prompt (yours might look different) cs-class-1% ls <--- lists the directory, which is empty cs-class-1% nano first.cc <--- opens nano with the empty file first.cc cs-class-1% ls <--- lists the directory, which now contains the new file first.cc cs-class-1% g++ first.cc <--- compiles the program to a.out, the default name cs-class-1% ls <--- lists the directory, which now contains the compiled program a.out a.out* first.cc cs-class-1% ./a.out <--- executes the program a.out The sum is 11 cs-class-1% mv a.out first.exe <--- renames a.out to first.exe cs-class-1% ls <--- lists the directory first.cc first.exe* cs-class-1% ./first.exe <--- executes the program first.exe The sum is 11 cs-class-1% rm first.exe <--- removes first.exe cs-class-1% ls <--- lists the directory, which now contains only first.cc first.cc cs-class-1% g++ -o first.exe first.cc <--- compiles first.cc to first.exe cs-class-1% ls <--- lists the directory, which now contains first.exe first.cc first.exe* cs-class-1% ./first.exe <--- runs the program first.exe The sum is 11 cs-class-1% mv first.exe a.out <--- moves first.exe to a.out cs-class-1% ls <--- lists the directory a.out* first.cc cs-class-1% ./a.out <--- runs the program a.out The sum is 11 cs-class-1% logout <--- terminates the session
Useful Linux and Unix Commands