Lesson 1 of 20Getting Started12 min

Your First C++ Program

Every C++ application begins with a source file and a main() function. In this lesson, you will create a console project, enter a short program, build it, and understand what each line does.

What You Will Learn

Create the Program

Create a new C++ Console App project, open the main .cpp file, and replace its contents with this code:

HelloWorld.cpp
#include <iostream>
using namespace std;

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

How the Program Works

CodePurpose
#include <iostream>Adds the standard input and output tools.
using namespace std;Lets this beginner example use cout and endl without the std:: prefix.
int main()Defines the starting point of the program.
coutSends text to the console window.
return 0;Reports that the program ended successfully.
Practice task

Change the message so that it displays your name and the sentence “I am learning C++.”

Lesson Summary

Write, build, and run a simple console program in Visual Studio 2026.