You are here

C++ hello world program

Hi! Are you searching for how to write a C++ hello world program? I hope I will be able to help you with that.

Hello world C++ program

#include <iostream> // Declaration of header

using namespace std; // Using std namespace

int main() // Function main through which program execution begins
{
  cout << "Hello World"; // Displaying "hello world"

  return 0; // Returning 0 indicates success to the operating system
}

C++ hello world program using a class

#include<iostream>

using namespace std;

// Creating class

class Message
{
  public:

    void display() {
      cout << "Hello World";
    }
};

int main()
{
    Message t;    // Creating an object
    t.display();  // Calling function

    return 0;
}