Instructions for C++ Programming under Unix Machines in the Undergraduate Lab
--------------------------------------------------------------------------------
Procedures to Run C++ Program under Unix in the Undergraduate Lab
1. Access your account by your Unix User name and password
2. Open the Command Prompt
3. Create a C++ program and save as a file
Type a text command such as "pico" or "vi" to edit you C++ program under command prompt.
For example, enters "pico helloworld.cpp". This step creates/opens a C++ file called "helloworld"
with the extension "cpp". Note : every C++ source file ends with "cpp".
4. Compile your c++ program:
After saving source code by command "Ctrl+x" for pico, next step is compiling your code.
Under the same directory of your C++ program, type "g++ yourfilename.cpp".
5. run the c++ program
After you compile your C++ program successfully, you can run it:
type "a.out" on the command line to run it. ("a.out" is your execution filename)
---------------------------------------------------------------------------------
p.s.
If you do not want to type a.out for every program, you can compile your program as
"g++ yourfilename.cpp -o executionname". Then every time you can type "executioname" to
run the specific program you want.
---------------------------------------------------------------------------------
Example 1
pike%pico helloworld.cpp
//source code for hello world in C++
#include <iostream.h>
int main()
{
cout<<"hello world"<<endl;
return 0;
}
pike%g++ helloworld.cpp
pike%a.out
hello world
//above line is the result from Unix.
Example 2
//source code for hello world in C++
#include <iostream.h>
int main()
{
cout<<"hello world"<<endl;
return 0;
}
pike%g++ helloworld.cpp -o helloworld
pike%helloworld
hello world
//above line is the result from Unix.