Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
55f0210
annotate new linkage info
TylerMSFT Sep 30, 2025
e383ea8
Merge branch 'main' of https://github.com/MicrosoftDocs/cpp-docs-pr i…
TylerMSFT Oct 1, 2025
a560495
edits
TylerMSFT Oct 2, 2025
cffe208
remove changes from _fstat and _stat
TylerMSFT Oct 2, 2025
09cc7d7
remove another
TylerMSFT Oct 2, 2025
c67cfc8
more uniform wording
TylerMSFT Oct 7, 2025
6b125cb
more finesse
TylerMSFT Oct 7, 2025
c575f42
edit
TylerMSFT Oct 7, 2025
d4bc317
edits
TylerMSFT Oct 7, 2025
b336108
stubs
TylerMSFT Oct 23, 2025
f4ca46e
new topic
TylerMSFT Oct 23, 2025
f011312
formatting
TylerMSFT Oct 23, 2025
4d35db6
draft
TylerMSFT Oct 24, 2025
39f1ff0
draft
TylerMSFT Oct 24, 2025
5f2c38f
draft
TylerMSFT Oct 24, 2025
a82c21e
draft
TylerMSFT Oct 24, 2025
9d771a9
Apply suggestions from code review
JillGrant615 Oct 24, 2025
7ccf905
Merge pull request #6127 from TylerMSFT/CopilotTopic
JillGrant615 Oct 24, 2025
9e74819
Merge branch 'main' of https://github.com/MicrosoftDocs/cpp-docs-pr i…
TylerMSFT Oct 24, 2025
b604129
update version
TylerMSFT Oct 24, 2025
e267562
fix stray version #
TylerMSFT Oct 24, 2025
7c6d126
fix one more stray
TylerMSFT Oct 24, 2025
d33d8b8
Update docs/c-runtime-library/reference/ctime-ctime32-ctime64-wctime-…
JillGrant615 Oct 24, 2025
d9bc7c1
Merge pull request #6101 from TylerMSFT/linkage-ai
JillGrant615 Oct 24, 2025
328df68
Merge pull request #6128 from MicrosoftDocs/main
learn-build-service-prod[bot] Oct 25, 2025
02127b9
Merging changes synced from https://github.com/MicrosoftDocs/cpp-docs…
Oct 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/build/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/build/media/github-copilot-fix-warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/build/media/github-copilot-open-chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/build/media/life-exe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
249 changes: 249 additions & 0 deletions docs/build/use-github-copilot-create-cpp-console-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
---
title: Use AI to create a C++ console application in Visual Studio
description: "Learn how to use GitHub Copilot to create a C++ app using Microsoft C++ in Visual Studio."
ms.date: 10/24/2025
ms.topic: "tutorial"
ms.custom:
- ai-assisted
- copilot-scenario-highlight
---

# Use AI to create a C++ console application in Visual Studio

This tutorial shows you how to use GitHub Copilot to quickly create a C++ console application in Visual Studio. You create a console version of Conway's Game of Life, a classic cellular automaton.

Conway's Game of Life was devised by mathematician John Conway. It consists of a grid of cells that can be either alive or dead. The game evolves automatically based on simple rules and produces complex, evolving patterns that demonstrate how intricate behavior can emerge from basic mathematical rules.

GitHub Copilot is an AI-powered coding assistant that helps you write code faster, reduce errors, and explore new solutions. Some benefits of using Copilot when coding in C++:
- Generate entire C++ functions or classes as you type.
- Suggest code completions based on plain-language comments or prompts.
- Get help with complex algorithms, data structures, and standard library usage.
- Learn new APIs and modern C++ patterns through in-context examples.
- Receive context-aware suggestions based on your comments or code.
- Debug errors in your code.
- Simplify and refactor existing code.

## Prerequisites

- Visual Studio 2022 or later with the **Desktop development with C++** workload installed.
- GitHub Copilot. For more information, see [Get started with GitHub Copilot](/visualstudio/ide/visual-studio-github-copilot-get-started).

To verify you have the C++ workload installed:
1. Open Visual Studio Installer
1. Select **Modify** next to your Visual Studio installation
1. Ensure **Desktop development with C++** is checked:

:::image type="content" source="media/desktop-development-cpp-workload.png" alt-text="Screenshot of the Visual Studio Installer with the Workloads tab selected. Desktop development with c++ is selected.":::

1. If it isn't installed, select it and choose **Modify**.

For more information about installing Copilot, see [Manage GitHub Copilot installation and state](/visualstudio/ide/visual-studio-github-copilot-install-and-states).

## Create a project

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.

1. Open Visual Studio and select **Create a new project**.
1. Search for "Console App" and select the **Console App** template for C++.

:::image type="complex" source="media/vs2019-choose-console-app.png" alt-text="Screenshot of the Create a new project dialog.":::
The Create a new project dialog is shown with the Console App template selected. The template says: Run code in a windows terminal. Prints hello world by default. Has the tags c++, Windows, and Console.
:::image-end:::

1. Select **Next**.
1. Set the project name to **Life** and choose the location for the project.
1. Select **Create**.
1. Once the project opens, find the `Life.cpp` file in Solution Explorer.
1. Open `Life.cpp` and delete the default "Hello, World!" code to start with a clean slate.

## Use Copilot to create an app

You prompt Copilot by describing the functionality you want. In this section, you'll learn how to prompt Copilot to generate an implementation of Conway's Game of Life.

1. Open the Copilot chat window by selecting the Copilot icon in the toolbar:

:::image type="content" source="media/github-copilot-open-chat.png" alt-text="Screenshot of the GitHub icon dropdown. Open Chat Window is selected.":::

1. In the chat window, enter the following prompt:
```copilot-prompt
Create a C++ console application that implements Conway's Game of Life. The program should:
- Use a 40x20 grid displayed with asterisks (*) for live cells and spaces for dead cells
- Start with a random initial pattern
- Display each generation for 500ms before showing the next
- Allow the user to press any key to exit the program
- Include proper headers and use standard C++ practices
- Clear the console between generations to provide an animation effect
```
1. Copilot generates C++ code for Conway's Game of Life.
1. Copy the generated code and paste it into your empty `Life.cpp` file.
1. Build the project by pressing **F6** or selecting **Build > Build Solution**.
1. Run the program by pressing **F5** or **Ctrl+F5**.

> [!NOTE]
> The exact code generated by Copilot may vary slightly from run to run and model to model, but the core functionality should be consistent. If the generated code doesn't compile immediately, you can ask Copilot to fix any compilation errors. Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

### Example of typical generated code structure

Your generated code will likely include these key components:

- Headers for console manipulation, random number generation, and timing
- A 2D array or vector to represent the game grid
- Functions to initialize the grid, apply Conway's rules, and display the current state
- A main loop that continues until a key is pressed

Here's an example of the code that Copilot generated using the previous prompt:

```cpp
// Code generated by GitHub Copilot
#include <iostream>
#include <chrono>
#include <thread>
#include <conio.h> // for _kbhit and _getch

using namespace std;

int step = 0;
const int rows = 20;
const int cols = 40;

void printGrid(int grid[rows][cols])
{
cout << "Step: " << step << endl;
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
cout << (grid[i][j] ? '*' : ' ');
}
cout << endl;
}
}

int countNeighbors(int grid[rows][cols], int x, int y)
{
int count = 0;
for (int i = -1; i <= 1; ++i)
{
for (int j = -1; j <= 1; ++j)
{
if (i == 0 && j == 0)
{
continue;
}

int ni = x + i;
int nj = y + j;
if (ni >= 0 && ni < rows && nj >= 0 && nj < cols)
{
count += grid[ni][nj];
}
}
}
return count;
}

void updateGrid(int grid[rows][cols])
{
int newGrid[rows][cols] = { 0 };
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
int neighbors = countNeighbors(grid, i, j);
if (grid[i][j] == 1)
{
newGrid[i][j] = (neighbors < 2 || neighbors > 3) ? 0 : 1;
}
else
{
newGrid[i][j] = (neighbors == 3) ? 1 : 0;
}
}
}
// Copy newGrid back to grid
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
grid[i][j] = newGrid[i][j];
}
}
}

int main()
{
int grid[rows][cols] = { 0 };

// Initial configuration (a simple glider)
grid[1][2] = 1;
grid[2][3] = 1;
grid[3][1] = 1;
grid[3][2] = 1;
grid[3][3] = 1;

while (true)
{
if (_kbhit()) // Check if a key has been pressed
{
_getch(); // Consume the key
break; // Exit the loop
}
printGrid(grid);
updateGrid(grid);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
cout << "\033[H\033[J"; // Clear the screen
step++;
}

return 0;
}
```
When you run the application, you should see an animated display of Conway's Game of Life with patterns evolving over time. To exit the program, press a key.

:::image type="content" source="./media/life-exe.png" alt-text="Screenshot of Conway Life running in a command window, displaying the evolving grid of cells.":::

In the preceding code example, the code generates a warning: `Return value ignored: '_getch'`. You can ask Copilot to fix it. Select the code editor and press **Alt+/** (Windows) to open the Copilot chat, then enter:

:::image type="content" source="./media/github-copilot-fix-warning.png" alt-text="Screenshot of the Copilot chat window. The text: Fix warning C6031 is in the chat window.":::

Copilot suggests a fix to handle the return value properly. To accept the changes, select **Tab**:

:::image type="content" source="./media/github-copilot-fix-warning-accept.png" alt-text="Screenshot of the Copilot proposed changes. Tab to accept. Alt+Del to discard.":::

Congratulations! You successfully used GitHub Copilot to create a fully functional Conway's Game of Life console application in C++. You learned how to:

- Craft an effective prompt to generate C++ code
- Use Copilot's chat interface to create an entire application from scratch
- Fix compilation warnings with AI assistance

## Improve your prompting skills

For better results with Copilot, see these prompting resources:

- [GitHub Copilot documentation](https://docs.github.com/en/copilot) - Official best practices and tips
- [OpenAI's GPT best practices](https://platform.openai.com/docs/guides/prompt-engineering) - General AI prompting techniques
- [Copilot prompting guide](https://github.blog/2023-06-20-how-to-write-better-prompts-for-github-copilot/) - Specific guidance for code generation

## Troubleshooting

### Missing console app template

The **New Project** dialog should show a **Console App** template that has **C++**, **Windows**, and **Console** tags. If you don't see it, 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.

To install **Desktop development with C++**, you can run the installer right from the **Create a new project** dialog. Choose the **Install more tools and features** link at the bottom of the **Create a new project** dialog, beneath the list of templates. 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.

### Copilot not responding

- Ensure you have an active GitHub Copilot subscription.
- Try signing out and back into your GitHub account in Visual Studio

### Generated code doesn't compile

- Ask Copilot to fix specific compilation errors by pasting the error message into Copilot chat.
- Try refining your prompt to be more specific about what you want the app to do.

## Next steps

- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot documentation](https://docs.github.com/en/copilot) - Dive deeper into AI-assisted development
- [Awesome ChatGPT Prompts](https://github.com/f/awesome-chatgpt-prompts) - Community-driven prompting examples for inspiration
4 changes: 1 addition & 3 deletions docs/build/vscpp-step-0-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Some benefits of using Copilot for your C++ coding scenarios:
- Debug errors in your code.
- Simplify and refactor existing code.

To install GitHub Copilot, see [Manage GitHub Copilot installation and state](/visualstudio/ide/visual-studio-github-copilot-install-and-states).
To try GitHub copilot to create a C++ app, follow the instructions in [Use AI to create a C++ console application in Visual Studio](../build/use-github-copilot-create-cpp-console-app.md).

::: moniker-end

Expand Down Expand Up @@ -225,9 +225,7 @@ You can reduce the installation footprint of Visual Studio on your system drive.
### Step 8 - Start developing

1. After Visual Studio installation is complete, choose the **Launch** button to get started developing with Visual Studio.

1. On the start window, choose **Create a new project**.

1. In the search box, enter the type of app you want to create to see a list of available templates. The list of templates depends on the workloads that you chose during installation. To see different templates, choose different workloads.

You can also filter your search for a specific programming language by using the **Language** dropdown list. You can filter by using the **Platform** list and the **Project type** list, too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ api_type: ["DLLExport"]
topic_type: ["apiref"]
f1_keywords: ["_wctime64", "_ctime32", "_tctime", "_wctime", "_wctime32", "_tctime64", "_ctime64", "ctime"]
helpviewer_keywords: ["tctime64 function", "_ctime32 function", "ctime32 function", "_wctime function", "wctime64 function", "_tctime64 function", "_tctime32 function", "_ctime64 function", "_wctime64 function", "ctime function", "wctime32 function", "ctime64 function", "_wctime32 function", "_tctime function", "tctime32 function", "tctime function", "wctime function", "time, converting"]
ms.assetid: 2423de37-a35c-4f0a-a378-3116bc120a9d
---
# `ctime`, `_ctime32`, `_ctime64`, `_wctime`, `_wctime32`, `_wctime64`

Expand All @@ -17,10 +16,10 @@ Convert a time value to a string and adjust for local time zone settings. More s
## Syntax

```C
char *ctime( const time_t *sourceTime );
char *ctime( const time_t *sourceTime ); // See note in remarks section about linkage
char *_ctime32( const __time32_t *sourceTime );
char *_ctime64( const __time64_t *sourceTime );
wchar_t *_wctime( const time_t *sourceTime );
wchar_t *_wctime( const time_t *sourceTime ); // See note in remarks section about linkage
wchar_t *_wctime32( const __time32_t *sourceTime );
wchar_t *_wctime64( const __time64_t *sourceTime );
```
Expand Down Expand Up @@ -62,9 +61,14 @@ These functions validate their parameters. If *`sourceTime`* is a null pointer,

By default, this function's global state is scoped to the application. To change this behavior, see [Global state in the CRT](../global-state.md).

> [!Note]
> When you use Windows SDK version 10.0.26100.6901 and Visual Studio 2026 or later together, `ctime` and `_wctime` are no longer `static inline` (internal linkage). Instead, they're `inline` (external linkage).\
> To return to the previous behavior, `#define _STATIC_INLINE_UCRT_FUNCTIONS=1` before including any CRT headers. By default, `_STATIC_INLINE_UCRT_FUNCTIONS` is set to 0.\
> This change increases UCRT conformance with the C++ standard and improves compatibility with C++ modules.

### Generic-text routine mappings

| TCHAR.H routine | `_UNICODE` and `_MBCS` not defined | `_MBCS` defined | `_UNICODE` defined |
| `TCHAR.H` routine | `_UNICODE` and `_MBCS` not defined | `_MBCS` defined | `_UNICODE` defined |
|---|---|---|---|
| `_tctime` | **`ctime`** | **`ctime`** | **`_wctime`** |
| `_tctime32` | **`_ctime32`** | **`_ctime32`** | **`_wctime32`** |
Expand All @@ -74,12 +78,12 @@ By default, this function's global state is scoped to the application. To change

| Routine | Required header |
|---|---|
| **`ctime`** | \<time.h> |
| **`_ctime32`** | \<time.h> |
| **`_ctime64`** | \<time.h> |
| **`_wctime`** | \<time.h> or \<wchar.h> |
| **`_wctime32`** | \<time.h> or \<wchar.h> |
| **`_wctime64`** | \<time.h> or \<wchar.h> |
| **`ctime`** | `<time.h>` |
| **`_ctime32`** | `<time.h>` |
| **`_ctime64`** | `<time.h>` |
| **`_wctime`** | `<time.h>` or `<wchar.h>` |
| **`_wctime32`** | `<time.h>` or `<wchar.h>` |
| **`_wctime64`** | `<time.h>` or `<wchar.h>` |

For more compatibility information, see [Compatibility](../compatibility.md).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Convert a time value to a string and adjust for local time zone settings. These
## Syntax

```C
errno_t ctime_s(
errno_t ctime_s( // See note in remarks section about linkage
char* buffer,
size_t numberOfElements,
const time_t *sourceTime
Expand All @@ -31,7 +31,7 @@ errno_t _ctime64_s(
size_t numberOfElements,
const __time64_t *sourceTime
);
errno_t _wctime_s(
errno_t _wctime_s( // See note in remarks section about linkage
wchar_t* buffer,
size_t numberOfElements,
const time_t *sourceTime
Expand Down Expand Up @@ -124,6 +124,11 @@ The debug library versions of these functions first fill the buffer with 0xFE. T

By default, this function's global state is scoped to the application. To change this behavior, see [Global state in the CRT](../global-state.md).

> [!Note]
> When you use Windows SDK version 10.0.26100.6901 and Visual Studio 2026 or later together, `ctime_s` and `_wctime_s` are no longer `static inline` (internal linkage). Instead, they're `inline` (external linkage).\
> To return to the previous behavior, `#define _STATIC_INLINE_UCRT_FUNCTIONS=1` before including any CRT headers. By default, `_STATIC_INLINE_UCRT_FUNCTIONS` is set to 0.\
> This change increases UCRT conformance with the C++ standard and improves compatibility with C++ modules.

### Generic-text routine mappings

| TCHAR.H routine | `_UNICODE` and `_MBCS` not defined | `_MBCS` defined | `_UNICODE` defined |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ api_type: ["DLLExport"]
topic_type: ["apiref"]
f1_keywords: ["_difftime64", "difftime", "difftime64", "_difftime32", "difftime32"]
helpviewer_keywords: ["_difftime32 function", "difftime function", "time, finding the difference", "difftime64 function", "_difftime64 function", "difftime32 function"]
ms.assetid: 4cc0ac2b-fc7b-42c0-8283-8c9d10c566d0
---
# `difftime`, `_difftime32`, `_difftime64`

Expand All @@ -17,7 +16,7 @@ Finds the difference between two times.
## Syntax

```C
double difftime( time_t timeEnd, time_t timeStart );
double difftime( time_t timeEnd, time_t timeStart ); // See note in remarks section about linkage
double _difftime32( __time32_t timeEnd, __time32_t timeStart );
double _difftime64( __time64_t timeEnd, __time64_t timeStart );
```
Expand Down Expand Up @@ -46,13 +45,18 @@ These functions validate their parameters. If either of the parameters is zero o

By default, this function's global state is scoped to the application. To change this behavior, see [Global state in the CRT](../global-state.md).

> [!Note]
> If you use Windows SDK version 10.0.26100.6901 and Visual Studio 2026 or later together, `difftime` is no longer `static inline` (internal linkage). Instead, it's `inline` (external linkage).\
> To return to the previous behavior, `#define _STATIC_INLINE_UCRT_FUNCTIONS=1` before including any CRT headers. By default, `_STATIC_INLINE_UCRT_FUNCTIONS` is set to 0.\
> This change increases UCRT conformance with the C++ standard and improves compatibility with C++ modules.

## Requirements

| Routine | Required header |
|---|---|
| **`difftime`** | \<time.h> |
| **`_difftime32`** | \<time.h> |
| **`_difftime64`** | \<time.h> |
| **`difftime`** | `<time.h>` |
| **`_difftime32`** | `<time.h>` |
| **`_difftime64`** | `<time.h>` |

For more compatibility information, see [Compatibility](../compatibility.md).

Expand Down
Loading