Saturday, August 8, 2009

How to Compile & Run C++ Program in Ubuntu linux

Well.... Compiling & running a C++ program in ubuntu linux is little bit tough. But don't worry, here I am to make it easy.
Step 1:: Put the C++ source code in a file with extension .cpp
Step 2:: Let the terminl know where you have saved the code. i.e. specify the path.
Step 3:: Write g++ filename.cpp -o test to compile it.
Step 4:: Now run it by using ./test.

You will see output of your program in terminal window.
During run time, you may have error, because coading of C++ in linux is little bizarre.
Here is the example::
#include<iostream>
main()
{
std::cout<<"testing"<<"\n";
}
Now you surely get the output.
Still getting errors??? Then make sure you have installed necessary package to run C++ program. If not, say terminal to install it by using
sudo apt-get install build-essential g++ & connect computer to internet.








1 comment: