Skip to content

Commit b336108

Browse files
committed
stubs
1 parent c9d832d commit b336108

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
---
2+
title: Create a C++ app with Copilot
3+
description: "Learn how to use Copilot to create your first C++ app using Microsoft C++ in Visual Studio."
4+
ms.date: 10/22/2025
5+
ms.topic: "tutorial"
6+
ms.custom:
7+
- "mvc"
8+
- copilot-scenario-highlight
9+
---
10+
# Create a C++ app with Copilot
11+
12+
The usual starting point for a C++ programmer is a "Hello, world!" application that runs on the command line. That's what you create in Visual Studio in this step.
13+
14+
## Prerequisites
15+
16+
- The **Desktop development with C++** workload must be installed to make the **Console App (C++)** project type available. If it's not installed, see [Install C++ support in Visual Studio](vscpp-step-0-installation.md).
17+
18+
## Create your project
19+
20+
Visual Studio uses *projects* to organize the code for an app, and *solutions* to organize your projects. A project contains all the options, configurations, and rules used to build your apps. It manages the relationship between all the project's files and any external files. To create your app, first, create a new project and solution.
21+
22+
1. In Visual Studio, open the **File** menu and choose **New > Project** to open the **Create a new Project** dialog. Select the **Console App** template that has **C++**, **Windows**, and **Console** tags, and then choose **Next**.
23+
24+
:::image type="complex" source="media/vs2019-choose-console-app.png" alt-text="Screenshot of the create a new project dialog.":::
25+
The create a new project dialog with the Console App template selected. That template says: Run code in a windows terminal. Prints hello world by default. Has the tags c++, Windows, and Console.
26+
:::image-end:::
27+
28+
The **Desktop development with C++** workload must be installed for the C++ Console App template to show up. See [Install C++ support in Visual Studio](vscpp-step-0-installation.md) if you haven't already installed it.
29+
30+
1. In the **Configure your new project** dialog, enter *HelloCopilot* in the **Project name** edit box. Choose **Create** to create the project.
31+
32+
:::image type="complex" source="media/vs2019-configure-new-project-hello-world.png" alt-text="Screenshot of Configure your new project dialog.":::
33+
The Configure your new project dialog with HelloWorld entered into the Project name field.
34+
:::image-end:::
35+
36+
Visual Studio creates a new project. It's ready for you to add and edit your source code. By default, the Console App template provides source code for a "Hello World" app, like this:
37+
38+
:::image type="complex" source="media/vs2019-hello-world-code.png" alt-text="Screenshot of the NEW Hello World project.":::
39+
Shows the new project. The HelloWorld.cpp file is open, showing the default code that is included with this template. That code consists of #include iostream and a main() function that contains the line: std::cout << quote hello world!\n quote;
40+
:::image-end:::
41+
42+
When the code looks like this in the editor, you're ready to go on to the next step and use Copilot top build an app.
43+
44+
You can use GitHub Copilot in Visual Studio to help with your C++ development. Copilot is an AI-powered coding assistant that helps you write code faster, reduce errors, and explore new solutions.
45+
46+
Some benefits of using Copilot when coding in C++:
47+
- Generate entire C++ functions or classes as you type.
48+
- Suggest code completions based on plain-language comments or prompts.
49+
- Get help with complex algorithms, data structures, and standard library usage.
50+
- Learn new APIs and modern C++ patterns through in-context examples.
51+
- Receive context-aware suggestions based on your comments or code.
52+
- Debug errors in your code.
53+
- Simplify and refactor existing code.
54+
55+
To install GitHub Copilot, see [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states).
56+
57+
## Use Copilot to create a Conway Life app
58+
59+
60+
## Prompting
61+
62+
Replace the default "Hello, World!" code with a simple implementation of Conway's Game of Life. You can do this by prompting Copilot with comments that describe the functionality you want. Here's an example of how to prompt Copilot to generate the code:
63+
64+
65+
```cpp
66+
// Code generated by GitHub Copilot
67+
#include <iostream>
68+
#include <chrono>
69+
#include <thread>
70+
#include <conio.h> // for _kbhit and _getch
71+
72+
using namespace std;
73+
74+
int step = 0;
75+
const int rows = 20;
76+
const int cols = 40;
77+
78+
void printGrid(int grid[rows][cols])
79+
{
80+
cout << "Step: " << step << endl;
81+
for (int i = 0; i < rows; ++i)
82+
{
83+
for (int j = 0; j < cols; ++j)
84+
{
85+
cout << (grid[i][j] ? '*' : ' ');
86+
}
87+
cout << endl;
88+
}
89+
}
90+
91+
int countNeighbors(int grid[rows][cols], int x, int y)
92+
{
93+
int count = 0;
94+
for (int i = -1; i <= 1; ++i)
95+
{
96+
for (int j = -1; j <= 1; ++j)
97+
{
98+
if (i == 0 && j == 0)
99+
{
100+
continue;
101+
}
102+
103+
int ni = x + i;
104+
int nj = y + j;
105+
if (ni >= 0 && ni < rows && nj >= 0 && nj < cols)
106+
{
107+
count += grid[ni][nj];
108+
}
109+
}
110+
}
111+
return count;
112+
}
113+
114+
void updateGrid(int grid[rows][cols])
115+
{
116+
int newGrid[rows][cols] = { 0 };
117+
for (int i = 0; i < rows; ++i)
118+
{
119+
for (int j = 0; j < cols; ++j)
120+
{
121+
int neighbors = countNeighbors(grid, i, j);
122+
if (grid[i][j] == 1)
123+
{
124+
newGrid[i][j] = (neighbors < 2 || neighbors > 3) ? 0 : 1;
125+
}
126+
else
127+
{
128+
newGrid[i][j] = (neighbors == 3) ? 1 : 0;
129+
}
130+
}
131+
}
132+
// Copy newGrid back to grid
133+
for (int i = 0; i < rows; ++i)
134+
{
135+
for (int j = 0; j < cols; ++j)
136+
{
137+
grid[i][j] = newGrid[i][j];
138+
}
139+
}
140+
}
141+
142+
int main()
143+
{
144+
int grid[rows][cols] = { 0 };
145+
146+
// Initial configuration (a simple glider)
147+
grid[1][2] = 1;
148+
grid[2][3] = 1;
149+
grid[3][1] = 1;
150+
grid[3][2] = 1;
151+
grid[3][3] = 1;
152+
153+
while (true)
154+
{
155+
if (_kbhit()) // Check if a key has been pressed
156+
{
157+
_getch(); // Consume the key
158+
break; // Exit the loop
159+
}
160+
printGrid(grid);
161+
updateGrid(grid);
162+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
163+
cout << "\033[H\033[J"; // Clear the screen
164+
step++;
165+
}
166+
167+
return 0;
168+
}
169+
```
170+
171+
172+
## Next steps
173+
174+
> [!div class="nextstepaction"]
175+
> [Build and run a C++ project](vscpp-step-2-build.md)
176+
177+
## Troubleshooting guide
178+
179+
Come here for solutions to common issues when you create your first C++ project.
180+
181+
### Create your app project: issues
182+
183+
The **New Project** dialog should show a **Console App** template that has **C++**, **Windows**, and **Console** tags. If you don't see it, there are two possible causes. It might be filtered out of the list, or it might not be installed. First, check the filter dropdowns at the top of the list of templates. Set them to **C++**, **Windows**, and **Console**. The C++ **Console App** template should appear; otherwise, the **Desktop development with C++** workload isn't installed.
184+
185+
To install **Desktop development with C++**, you can run the installer right from the **New Project** dialog. Choose the **Install more tools and features** link at the bottom of the template list to start the installer. If the **User Account Control** dialog requests permissions, choose **Yes**. In the installer, make sure the **Desktop development with C++** workload is checked. Then choose **Modify** to update your Visual Studio installation.
186+
187+
If another project with the same name already exists, choose another name for your project. Or, delete the existing project and try again. To delete an existing project, delete the solution folder (the folder that contains the `helloworld.sln` file) in File Explorer.
188+
189+
[Go back](#create-your-app-project).
190+

docs/get-started/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ items:
66
href: ../build/vscpp-step-0-installation.md
77
- name: Visual Studio guided tour
88
href: /visualstudio/get-started/visual-studio-ide
9+
- name: Create a C++ app with Copilot
10+
href: ../build/create-cpp-app-with-github-copilot.md
911
- name: Create and edit a C++ console app project
1012
href: ../build/vscpp-step-1-create.md
1113
- name: Build and run a C++ console app project

0 commit comments

Comments
 (0)