Linux News|Linux Install sidebyside windows|Ubuntu|Linux Help|Installing Apache and php from source

Friday, January 6, 2012

Running a C/C++ program in ubuntu

First check for the compiler installation as follows on your terminal:
[g++ --version]
if it gives the version of your compiler then run the programs as given below other wise just go through this tutorial:
Installing C/C++ compiler in Ubuntu

Running a c++ program

using namespace std;
int main()
cout<<"Hello world"<<endl;

Save it as first.cpp on your desktop.
Open the terminal and do as follows.
[g++ Desktop/first.cpp -o Desktop/first.o]
                                                      first.o will be created if no error occurs
[cd Desktop]

Running a C program

//using namespace std;
int main()
printf("Hello world\n");

Save it as second.c on your Desktop.

[g++ Desktop/second.c -o Desktop/second.o]
[cd Desktop]

Here you can use gcc or g++ as g++ supports both.

If you have any question then write down the comments,I will be pleased to help you.

No comments:

Post a Comment