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 a C++ console project in Visual Studio 2026.
- Recognise the purpose of
#include <iostream>. - Display text with
cout. - Build and run the program.
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
| Code | Purpose |
|---|---|
#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. |
cout | Sends 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.