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


#include<iostream>
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]
[./first.o]

Running a C program


#include<stdio.h>
//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]
[./second.o]

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.

3 comments:

  1. An impressive share! I have just forwarded this onto a coworker who had been conducting a little homework on this technology. And he in fact bought me dinner due to the fact that I found it for him... lol. So allow me to reword this.... Thank YOU for the meal!! But yeah, thanx for spending time to discuss this topic here on your website.

    ReplyDelete

ubuntuway.blogspot.com