Choose one development path
For a first C++ program on Windows, use Visual Studio with the Desktop development with C++ workload. This gives you an editor, project templates, the MSVC compiler and linker, a Windows SDK and a debugger in one setup. Visual Studio Community is an option for individual learners; organisations should check Microsoft’s current licence terms before choosing an edition. You do not need a separate GCC installation to follow this path.
Visual Studio Code is a lighter editor, not the same product as Visual Studio. Its C/C++ extension does not include a compiler. MSYS2 with MinGW-w64 GCC is a useful alternative when a project specifically wants a GCC-style Windows toolchain. Start with one toolchain and its own terminal rather than installing several at once and mixing their build commands.
Install Visual Studio and the C++ workload
Go to Microsoft’s official Visual Studio download page and choose a supported stable Windows edition appropriate to your use. Run its installer, then select the Desktop development with C++ workload. Check that the installation details include an MSVC C++ toolset and a Windows SDK, and complete the installation. The exact installer layout and component versions can change; the workload name is the important choice for a basic native console program.
If Visual Studio is already installed, open Visual Studio Installer from the Start menu, choose Modify for that installation, select the same workload and apply the change. Installing Visual Studio without this workload can leave you with an editor but no C++ project template or compiler. You do not need unrelated game, web or .NET workloads for this first console program.
- Download Visual Studio from Microsoft and start the Visual Studio Installer.
- Select Desktop development with C++ and confirm the MSVC tools and Windows SDK in the installation details.
- Install, then launch Visual Studio. Use the installer’s Modify action later if the C++ workload is missing.
Understand the Microsoft C++ toolchain
MSVC is more than the editor. Its cl.exe driver checks and compiles C++ source, the linker combines compiled files, and the installed headers and libraries provide the C++ standard library and Windows platform APIs. Visual Studio uses projects and solutions to remember source files, build settings and targets. The Windows SDK supplies platform headers and libraries; it is not the C++ language itself.
You can build inside Visual Studio without manually opening a terminal. For command-line work, use the Developer Command Prompt or an appropriate Native Tools Command Prompt that the installer creates. That prompt sets paths for cl.exe, headers and libraries. A normal Command Prompt or PowerShell window often does not have those settings. Do not copy a bare cl command into PowerShell and assume it will find MSVC.
Verify compiler availability
From the Windows Start menu, open the Developer Command Prompt for your installed Visual Studio version. Type cl. It should print the Microsoft C/C++ compiler version and usage text. Because no source file was provided, it can finish with a nonzero status; the visible version and usage text are what you are checking. The shortcut may open in an installation directory, so change to your own project folder before creating files.
If cl is not recognised there, use Visual Studio Installer to confirm the Desktop development with C++ workload, MSVC toolset and Windows SDK are installed. If cl works in the developer prompt but not in ordinary PowerShell, that is a shell-environment difference, not evidence that the compiler is broken. Visual Studio’s Build menu configures this environment for IDE projects automatically.
In Developer Command Prompt for Visual Studio
clCreate, build and run a console project
Launch Visual Studio and choose Create a new project. Filter the language to C++, the platform to Windows and search for Console App. Select the template tagged C++ and Windows, name the project CppHello, choose a folder you own, then select Create. Visual Studio creates a project and solution and opens a generated .cpp file. Keep its generated main function or replace the file contents with the complete example below; do not leave two main functions in the same project.
Choose Build > Build Solution and read the Output window if the build fails. Then choose Debug > Start Without Debugging, or press Ctrl+F5, to build and run the console app. The terminal should show Hello, Codectionary!. Change the message, build again and rerun to see your edit. F5 starts with debugging; Ctrl+F5 is simpler for this first output check. A Visual Studio Console App is a native C++ project, not a C#/.NET Console App.
Replace the generated .cpp contents with this complete program
#include <iostream>
int main() {
std::cout << "Hello, Codectionary!" << '\n';
return 0;
}PowerShell, Command Prompt and the MSYS2 alternative
Visual Studio’s build and run buttons need no shell command. In the Visual Studio Developer Command Prompt, cl /EHsc /std:c++17 hello.cpp builds a standalone file and creates hello.exe; type hello.exe to run it. In PowerShell, a local executable is run as .\hello.exe, but first open a PowerShell session configured for MSVC or use the developer prompt to build. Ordinary Command Prompt can run hello.exe from its current folder after the file exists, but it does not automatically know where cl.exe and its libraries are.
If you specifically need GCC on Windows, MSYS2 offers a MinGW-w64 toolchain. Its official setup starts the UCRT64 terminal and installs mingw-w64-ucrt-x86_64-gcc with pacman; that package includes g++. Use the UCRT64 terminal and its g++ command, not the MSVC developer prompt, for that workflow. Package prefixes and architecture differ in other MSYS2 environments. This is an alternative path, not a second required installation, and a project’s binaries and libraries should match its chosen toolchain.
Optional: standalone file in an MSVC Developer Command Prompt
cl /EHsc /std:c++17 hello.cpp
hello.exeOptional: MSYS2 UCRT64 terminal after installing MSYS2
pacman -S mingw-w64-ucrt-x86_64-gcc
g++ --versionCommon Windows setup problems
If Console App is missing, remove restrictive project-template filters and confirm the Desktop development with C++ workload in Visual Studio Installer. If cl is not recognised, use the developer prompt and verify the MSVC toolset. Errors about missing Windows headers or libraries often indicate an incomplete workload, missing Windows SDK or a normal shell that lacks the developer environment. A compiler diagnostic about your .cpp line is a different issue: read the first error and correct the code.
If the program appears to close instantly, run it with Ctrl+F5 or from a terminal so you can read its output. If your changes do not appear, save the file, rebuild and ensure you launched the updated project or executable. If you chose MSYS2, open its UCRT64 terminal and check g++ --version there; do not assume a g++ installed in one MSYS2 environment is available in every Windows shell.
Syntax
#include <iostream>
int main() {
std::cout << "Hello, Codectionary!" << '\n';
return 0;
}Examples
First Windows C++ console program
Paste this into the C++ Console App source file, then build and run with Ctrl+F5.
#include <iostream>
int main() {
std::cout << "Hello, Codectionary!" << '\n';
return 0;
}- The goal is to check that your Visual Studio C++ workload can build and run a native console application.
- #include <iostream> provides std::cout. The main function is the starting point for this program, and its braces enclose the statements.
- The stream insertion operators send a string and a newline to standard output, so the console shows Hello, Codectionary!. return 0 reports successful completion.
- If the template already contains a main function, replace its contents rather than adding a second one. After changing the message, rebuild before judging the new output.
Best practices
- Begin with one compiler path: Visual Studio and its C++ workload for this Windows walkthrough.
- Use the Visual Studio developer prompt for MSVC command-line work, and keep MSYS2 UCRT64 commands in its own terminal.
- Read build diagnostics in the Output window and distinguish missing tools from mistakes in your source.
Runtime & versions
Compiled native applications. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
ISO C++ resources