Thursday, June 12, 2008

How to write and compile C++ programme in Linux

This is a very common problem for the new users of linux. People know the coding in C++ but don’t know how to run in linux. I noticed, because of this only people lose the interest in linux. It’s simple and here is how it's done.

· First start the terminal. Application>Accessories>Terminal

· Write the command sudo apt-get install gedit and sudo apt-get install g++


gedit is a text editor in Linux like notepad in windows and g++ is the compiler like c++. These statements install the gedit and g++ if not present or upgrade if present.

· Make a folder which contains your executable file. Write

sudo mkdir test

cd test

sudo gedit dummy.cpp

mkdir test - creates a folder named test.

cd test – opens the test folder

gedit dummy.cpp – creates a file dummy in gedit

· With this command gedit opens. Write the c++ code and save it. File>Save

· Now in the terminal write sudo g++ dummy.cpp. It compiles your code

· ./a.out . This command executes the code and the result is displayed on the terminal itself.

I have tried to make it understandable by keeping it simple. If you still have any doubts please feel free to write.

1 comment:

haruhi said...

hi
thanks alot
u help me soooooooooooo much
i realy don't know how to thank u