How do I write, compile, and run a simple 'Hello, World!' program in C++?

To write, compile, and run a simple 'Hello, World!' program in C++, follow these steps:

  1. Open a text editor (like Notepad for Windows or nano for Linux).
  2. Write the following C++ code:
  3. #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; return 0; }
  4. Save the file with a .cpp extension, for example, hello.cpp.
  5. Open your terminal or command prompt.
  6. Navigate to the directory where you saved your file.
  7. Compile the program. Depending on your system, use the following command:
  8. g++ hello.cpp -o hello
  9. Run the compiled program:
  10. ./hello
  11. You should see the output: Hello, World!

C++ Hello World programming compiler g++ code example