The "Hello, World!" program is a classic and simple program that is often used to introduce a new programming language. In the C++ programming language, the "Hello, World!" program is typically written as follows

Create a file

  1. Open a text editor or IDE. You will be writing your C++ code in this text editor or IDE.
  2. Start a new file and save it with a .cpp extension. For example, hello.cpp.
  3. Write the below code in your text editor or IDE:
  4. Save the file

Code

C++
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
  1. #include <iostream>: This line includes the iostream library, which provides input/output functions such as cout.
  2. int main(): main is the entry point of a C++ program. It returns an int value and takes no arguments.
  3. std::cout << "Hello, World!" << std::endl;: This line uses the cout function from the iostream library to print the string "Hello, World!" to the console. The std::endl at the end adds a new line character.
  4. return 0;: The return 0 statement signifies that the program executed successfully and returns the value 0 to the operating system.

Run in GCC Compiler

  1. Open a terminal or command prompt window and navigate to the directory where you saved your .cpp file.
  2. Compile your code by typing g++ hello.cpp -o hello and pressing Enter. This command compiles the code using the g++ compiler and outputs an executable file named hello.
  3. Run your program by typing ./hello and pressing Enter.

Run in Turbo C++ Compiler

To run the "Hello, World!" program in Turbo C++, you can follow these steps:

  1. Open the Turbo C++ IDE (Integrated Development Environment) by double-clicking on the Turbo C++ icon or running the TC.exe file in the Turbo C++ installation folder.
  2. Go to the "File" menu and select "New" to create a new file. This will open an editor window where you can type in the C code for the "Hello, World!" program.
  3. Copy and paste or Type the code from the previous example into the editor window:
  4. Go to the "File" menu and select "Save As". Select "All files" and give your file a name with the ".cpp" extension (e.g. "hello.cpp")
  5. Go to the "Compile" menu and select "Compile" (or press F9 on the keyboard) to compile the program. This will check the code for any syntax errors. If there are any errors, they will be displayed in a separate window, and you will need to fix them before proceeding.
  6. If the program compiles successfully, go to the "Run" menu and select "Run" (or press Ctrl + F9) to execute the program.

And that's it! You have written your first "Hello, World!" program in C++.