×
0 Interaction
1.1K Views
Views
15 Likes

C++ Hello World Tutorial

Welcome to C++ programming! In this tutorial, you will learn how to create, compile, and run your first C++ program: "Hello, World!".

1. Writing Your First Program

Create a new file named hello.cpp and add the following code:


#include <iostream>
using namespace std;

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

This code outputs the message "Hello, World!" to the console.

2. Compiling the Program

To compile your program, use a terminal or an IDE:

  • Terminal: Run the command: g++ hello.cpp -o hello.
  • IDE: Use the build/run feature of your chosen IDE.

3. Running the Program

After compiling, run the program:


./hello
                

You should see the output: Hello, World!.

4. Explanation of the Code

Key components of the program:

  • #include <iostream>: Includes the library for input/output operations.
  • using namespace std;: Simplifies access to standard library features.
  • int main(): Entry point of the program.
  • cout: Outputs text to the console.

5. Next Steps

Now that you've written your first program, explore additional topics like variables, loops, and functions to build your skills.

You need to be logged in to participate in this discussion.

×
×