Hello World & Setup

Lesson 4
Author : Afrixi
Last Updated : November, 2022
C++ - Programming Language
This course covers the basics of programming in C++.

Hello World & Setup

To get started with C++, you’ll need to set up a development environment and create a simple “Hello, World!” program. Here are the steps you can follow:

Step 1: Install a C++ compiler and code editor/IDE

To write, compile, and run C++ code, you need a C++ compiler and a code editor or integrated development environment (IDE). There are several options available for C++ development, including Visual Studio, Code::Blocks, and Eclipse. For Windows, you can use the Microsoft Visual Studio IDE, which includes a C++ compiler. For Mac, you can use Xcode, which also includes a C++ compiler. Another popular option is to use an online IDE, such as Repl.it or Code::Blocks online.

Step 2: Create a new C++ project

In your code editor or IDE, create a new C++ project. This will create a new workspace with a default project structure. Give your project a name and select a directory where you want to save your project files.

Step 3: Write your “Hello, World!” program

Open the main.cpp file (or create a new one) in your project and type the following code:

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

This code uses the iostream library to output the text “Hello, World!” to the console.

Step 4: Compile and run your program

Save your file and compile your program. In Visual Studio, you can click “Build” -> “Build Solution”. In Xcode, you can click “Product” -> “Build”. In Code::Blocks, you can click “Build” -> “Build”.

After compiling your program, run it by clicking “Debug” -> “Start Debugging” in Visual Studio or “Product” -> “Run” in Xcode. In Code::Blocks, click “Build and Run” or press F9.

You should see the output “Hello, World!” printed in the console.

Congratulations, you have now created your first C++ program! From here, you can explore C++ further by learning about variables, functions, classes, and other C++ concepts.