Wednesday, 27 August 2014

C++ hello world program

This is the first C++ program which simply prints Hello World on output screen.As you know that  in C++ the object cin and cout are used instead of scanf() and printf() function in C.

C++ hello world program

C++ hello world program

#include<iostream.h>
#include<conio.h>
 void main()
   {
       cout<<"\n Hello World ";
       getch();
   }

Output

Hello World


C++ hello world program using class

#include<iostream>
 
// Creating class
 
class Message
{
  public:
 
    void display() {
      cout << "Hello World\n";
    }
};
 
int main()
{
 Message c;    // Creating object
 c.display();  // Calling function
 
 return 0;
}


Output

Hello World