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.

0 Interaction
1.1K Views
Views
15 Likes
×
×
🍪 CookieConsent@Ptutorials:~

Welcome to Ptutorials

Note: We aim to make learning easier by sharing top-quality tutorials.

We kindly ask that you refrain from posting interactions unrelated to web development, such as political, sports, or other non-web-related content. Please be respectful and interact with other members in a friendly manner. By participating in discussions and providing valuable answers, you can earn points and level up your profile.

$ Allow cookies on this site ? (y/n)

top-home