Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/MicrosoftDocs/cpp-docs/llms.txt

Use this file to discover all available pages before exploring further.

Visual Studio organizes C++ development around two concepts: solutions and projects. A project is a set of source files, headers, and configuration rules that produce a single output — an executable, a DLL, or a library. A solution is a logical container that groups one or more related projects together, letting them share build configurations and reference each other. When you create a new C++ app in Visual Studio, you create both a solution and a project at the same time. This page walks you through that process for a console application — the simplest type of C++ program and the best starting point for learning the toolchain.

Prerequisites

The Desktop development with C++ workload must be installed before the C++ Console App project template will appear. If you haven’t installed it yet, see the Installation guide.

Creating the Project

1

Open the 'Create a New Project' Dialog

Launch Visual Studio. On the Start Window, click Create a new project. If Visual Studio is already open, use the menu: File > New > Project (or press Ctrl+Shift+N).
2

Select the Console App Template

In the Create a new project dialog, use the three filter dropdowns at the top to narrow the template list:
  • Language: C++
  • Platform: Windows
  • Project type: Console
Select the Console App template — it should display the tags C++, Windows, and Console and show a brief description: “Run code in a Windows terminal. Prints Hello World by default.” The icon has ”++” in the corner to distinguish it from the C# version.Click Next.
There are multiple “Console App” templates in Visual Studio — for C#, Visual Basic, and C++. Always verify the C++, Windows, Console tags before clicking Next. Selecting the wrong language template is a common beginner mistake.
3

Configure the New Project

The Configure your new project dialog has three fields:
  • Project name — Enter HelloWorld. This names the .vcxproj file and the final executable.
  • Location — Where on disk to create the solution folder. The default is Documents\Visual Studio 2022\Projects\.
  • Solution name — Defaults to match the project name. For a single-project solution this is fine; in larger codebases you might give the solution a different, higher-level name.
Leave Place solution and project in the same directory unchecked for now — keeping them separate is good practice for multi-project solutions.Click Create.
4

Review the Generated Project

Visual Studio creates the solution and project, and opens HelloWorld.cpp in the editor. The generated code looks like this:
// HelloWorld.cpp : This file contains the 'main' function.
// Program execution begins and ends there.
//

#include <iostream>

int main()
{
    std::cout << "Hello World!\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
This is a complete, valid C++ program. The #include <iostream> line brings in the Standard Library’s input/output stream header. The main() function is the entry point that the operating system calls when your executable starts. std::cout writes text to the standard output stream (the console window).

Understanding the Solution Structure

After project creation, the Solution Explorer panel (usually docked on the right or left side) shows the layout of your solution:
Solution 'HelloWorld' (1 of 1 project)
└── HelloWorld
    ├── References
    ├── External Dependencies
    ├── Header Files
    ├── Resource Files
    └── Source Files
        └── HelloWorld.cpp
The root node represents the .sln file on disk. A solution can contain multiple projects; right-click the solution to add existing or new projects.
Represents HelloWorld.vcxproj — the MSBuild project file that stores all build settings, compiler flags, preprocessor definitions, and file lists.
A virtual filter grouping your .cpp implementation files. Right-click here to add new or existing C++ source files. The actual files live on disk wherever your project folder is — the filter structure in Solution Explorer does not have to match the folder structure on disk.
A virtual filter for .h and .hpp files. Header files are not compiled directly; they are #include-d by source files.
Shows headers from the Windows SDK, the C++ Standard Library, and any other include paths configured in the project. These are auto-discovered by IntelliSense and are read-only.

Key Files on Disk

Navigate to your project folder in File Explorer to see the files Visual Studio created:
FileDescription
HelloWorld.slnSolution file. Open this in Visual Studio to load the solution.
HelloWorld\HelloWorld.vcxprojThe MSBuild project file containing all build settings.
HelloWorld\HelloWorld.vcxproj.filtersDefines the virtual folder structure shown in Solution Explorer.
HelloWorld\HelloWorld.cppYour main source file.
The .vs\ hidden directory next to the .sln file stores local user settings (window layouts, recently opened files, IntelliSense caches). It should generally be added to .gitignore and not committed to source control.

Understanding the Generated main() Function

The main() function is the program’s entry point. For a console application, the operating system calls main() at startup and the program exits when main() returns. The return value (an int) is the program’s exit code — 0 conventionally means success, any non-zero value indicates an error.
int main()
{
    std::cout << "Hello World!\n";
    // Implicitly returns 0 when execution reaches the end of main()
}
You can also declare main with command-line parameters:
int main(int argc, char* argv[])
{
    // argc: number of arguments (always at least 1)
    // argv: array of C-string pointers; argv[0] is the program name
    std::cout << "Program: " << argv[0] << "\n";
    return 0;
}

Adding More Source Files

Real projects are split across multiple files. To add a new .cpp or .h file:
  1. Right-click Source Files (or Header Files) in Solution Explorer.
  2. Choose Add > New Item… (or press Ctrl+Shift+A).
  3. Select C++ File (.cpp) or Header File (.h), give it a name, and click Add.
Visual Studio creates the file, adds it to the project, and opens it in the editor.

Next Steps

Now that your project is created and you understand its structure, the next step is to build and run it. Press Ctrl+Shift+B to compile, or continue to the Build and Run guide for a detailed walkthrough of the build process, the Output window, and the Error List.

Build docs developers (and LLMs) love