<?xml version="1.0" encoding="utf-8" ?>
<vst:Guide xmlns="http://schemas.microsoft.com/winfx/2001/xaml/presentation"
    xmlns:vst="clr-namespace:Microsoft.VisualStudio.Guide;assembly=Microsoft.VisualStudio.Shell.UI.Internal" 
    Title="Welcome to Visual Studio: Part 2 (C++)"
    Description="Learn the basics of C++ programming in Visual Studio." 
    RequiredPackageNames="Microsoft.VisualStudio.Component.CoreEditor,Microsoft.VisualStudio.Component.VC.CoreIde"
    Id="Welcome.Cpp" 
    SortOrder="012" 
    EstimatedMinutesToComplete="6" 
    ShowInStartPage="false"
    IconPath="Welcome.Cpp.ico">

    <vst:Guide.Solution>
        <vst:NewSolution Name="Welcome.Cpp">
            <vst:NewSolution.Projects>
                <vst:NewProjectFromSourceProject Name="Welcome.Cpp"
                                                 CreateInSolutionFolder="true"
                                                 ProjectFileExtension="vcxproj"/>
            </vst:NewSolution.Projects>
        </vst:NewSolution>
    </vst:Guide.Solution>

    <vst:Step Title="Welcome to Visual Studio: Part 2" 
        Id="Welcome.Cpp.Intro">
        <vst:Step.Description>
            <![CDATA[
In this guide, you'll get a brief introduction to editing and debugging with the Visual Studio IDE with **C++**. 

This is Part 2 of the *Welcome to Visual Studio* guide. If you haven't already, you should complete [Part 1](vscmd://Help.StartGuide?args=Welcome), which introduces you to the Visual Studio IDE.

In this guide, you'll learn how to edit and debug a simple C++ console application, including:

- Running the application.
- Using IntelliSense to write code faster.
- Using Quick Actions window to find and apply code fixes.
- Debugging the application at run time.
- Setting breakpoints and stepping through code.
- Inspecting variables and the call stack.

Ready to start? Select **Continue** to begin!
            ]]>
        </vst:Step.Description>
    </vst:Step>
    <vst:Step Title="Running your app" 
        Id="Welcome.Cpp.Run"
        FileToOpen="Welcome.Cpp.cpp"
        CommandToHighlight="6E87CFAD-6C05-4adf-9CD7-3B7943875B7C,0x0100">
        <vst:Step.Description>
            <![CDATA[
We've created a C++ project for you. You should see **Welcome.Cpp.cpp** open in the editor. This is the file you'll be working with in this guide.

To run the application, select [**Debug** > **Start Debugging**](vscmd://Debug.Start) {KeyboardShortcut:Debug.Start} from the menu bar. You can also use this button on the toolbar:

![Screenshot of the Start Debugging button in the toolbar](Welcome.Cpp.Run.StartDebugging.png)

The application will run and prompt you to enter a name. Enter a name and press `Enter`. The application will then display a greeting.

![A screenshot of the application running in the console window. The user has been prompted for their name. The user has responded, and the output message is displayed. The program loops and the user entered their name the second time.](Welcome.Cpp.Run.png)

The program is written to loop forever. End the program by selecting [**Debug** > **Stop Debugging**](vscmd://Debug.StopDebugging) {KeyboardShortcut:Debug.StopDebugging} from the menu bar or clicking this button on the toolbar:

![Screenshot of the Stop Debugging button in the toolbar](Welcome.Cpp.Run.StopDebugging.png)

Next we're going to make some changes to the code. Select **Continue** to proceed.
            ]]>
        </vst:Step.Description>
    </vst:Step>
    <vst:Step Title="Using IntelliSense to write code faster" 
        Id="Welcome.Cpp.Editing"
        FileToOpen="Welcome.Cpp.cpp"
        CenterLineNumber="20">
        <vst:Step.Description>
            <![CDATA[
The console output from the app is a little crowded. Let's add a space between each iteration of the loop to make it easier to read.

Place the text caret at the end of line 20. Press `Enter` to create a new line and then type the following characters: `s` `t` `d`. As you're typing, notice the window that appears. This is **IntelliSense** offering suggestions, and it's a great way to write code faster. It shows you the most likely completions for the text you're typing. When the suggestion you want appears, you can press `Tab` or `Enter` to accept it. 

In this case, there's nothing to accept since you've already typed the full word. You can press `Esc` to dismiss the window, or you can just keep typing.

Type `::` (the scope operator) to get suggestions for what to type next. Notice that the suggestions are filtered to only show the members of the `std` namespace. Type `c` `o` `u` and then select `cout` from the list with the arrow keys and press `Tab` or `Enter` to accept it.

Finally, complete the statement so that it sends a newline character to the `cout` object. The complete line should look like this:

```cpp
std::cout << "\n";
```

![An animation showing IntelliSense. The cursor is at the end of line 20. The user presses Enter to create a new line. The user types `s` `t` `d`. IntelliSense appears and shows the user the most likely completions. The user presses `Esc` to dismiss the window. The user types `::` and IntelliSense shows the members of the `std` namespace. The user types `c` `o` `u` and selects `cout` from the list with the arrow keys. The user presses `Tab` to accept the suggestion.](Welcome.Cpp.Editing.IntelliSense.mp4)

If you have **IntelliCode** enabled (it's enabled by default), in many contexts the most common IntelliSense completions will be at the top of the list of suggestions. These suggestions are denoted with a ⭐ (star) character.

- [Learn more about editing with IntelliSense](https://learn.microsoft.com/visualstudio/ide/using-intellisense)
- [Learn more about IntelliCode suggestions](https://learn.microsoft.com/visualstudio/intellicode/overview)

Select **Continue** to learn how to use Quick Actions to speed up your editing and refactoring.
            ]]>
        </vst:Step.Description>
    </vst:Step>
    <vst:Step Title="Quick Actions and Refactoring"
        Id="Welcome.Cpp.QuickActions"
        FileToOpen="Welcome.Cpp.cpp"
        CenterLineNumber="13">
        <vst:Step.Description>
            <![CDATA[
Visual Studio uses Quick Actions to make suggestions for code changes. You can use these suggestions to apply code fixes and refactorings.

Select all of lines 13 and 14, and then press `Ctrl+.` (period). A screwdriver icon appears in the margin with several suggestions. 

![A screenshot of the screwdriver icon next to lines 13 and 14](Welcome.Cpp.QuickActions.png)

These suggestions are called **Quick Actions**. You invoked the Quick Action menu yourself, but if Visual Studio There are different types of Quick Action suggestions, denoted by lightbulb and screwdriver icons. In this case, the screwdriver indicates the suggestions are code fixes.

Select the **Extract function** Quick Action to apply the code fix. Visual Studio will extract the code into a new method and call it from the original location. You're then prompted to name the method. Type *GetName* and press `Enter`.

Visual Studio shows the new method in the editor in an embedded code window. You can review the code in the embedded window. When you're done, select the **Close** button to close the embedded window.

![An animation showing the Quick Actions menu. The user selects the Extract function Quick Action. Visual Studio prompts the user to name the method. The user types *GetName* and presses Enter. Visual Studio shows the new method in an embedded code window. The user selects the Close button to close the embedded window.](Welcome.Cpp.QuickActions.mp4)

Visual Studio automatically analyzes your code as you're writing it and offers Quick Action suggestions. When you see the icon, you can select it or press `Ctrl+.` to see the suggestions.

- [Learn more about Quick Actions](https://learn.microsoft.com/visualstudio/ide/quick-actions)
- [Learn more about refactoring in Visual Studio](https://learn.microsoft.com/visualstudio/ide/refactoring-in-visual-studio)

Select **Continue** to learn how to debug using breakpoints.
            ]]>
        </vst:Step.Description>
    </vst:Step>
    <vst:Step Title="Debugging with breakpoints"
        Id="Welcome.Cpp.Debugging"
        FileToOpen="Welcome.Cpp.cpp"
        CenterLineNumber="14"
        CommandToHighlight="6E87CFAD-6C05-4adf-9CD7-3B7943875B7C,0x0100">
        <vst:Step.Description>
            <![CDATA[
Visual Studio supports a number of debugger tools to help you understand what your code is doing at runtime. Let's start by adding a breakpoint that will pause the execution of the program when it's reached.

Place the text caret anywhere on line 14 and select [**Debug** > **Toggle Breakpoint**](vscmd://Debug.ToggleBreakpoint) {KeyboardShortcut:Debug.ToggleBreakpoint} from the menu bar to add a breakpoint. The breakpoint will appear in the left margin as a red dot. You can also add a breakpoint by clicking in the margin.

![A screenshot of the breakpoint in the left margin next to line 14](Welcome.Cpp.Debugging.png)

Now let's run the program in debug mode again. Select [**Debug** > **Start Debugging**](vscmd://Debug.Start) {KeyboardShortcut:Debug.Start} from the menu bar or click the button on the toolbar. The program will run and stop at the breakpoint before the `GetName` method is called. Accordingly, there is no prompt for input yet.

Take a moment to examine the debugger tools.

The [**Autos**](vscmd://Debug.Autos) window shows all variables used on the current line or the preceding line. In this case, the `name` variable is an empty string because it hasn't been assigned a value yet. `iteration` is `1` because the loop is on its first iteration.

![A screenshot of the Autos window showing the `name` and `iteration` variables](Welcome.Cpp.Debugging.Autos.png)

The [**Locals**](vscmd://Debug.Locals) window shows all variables in scope. In this case, that includes the variables mentioned earlier.

![A screenshot of the Locals window showing the `name` and `iteration` variables.](Welcome.Cpp.Debugging.Locals.png)

The [**Call Stack**](vscmd://Debug.CallStack) window shows the call stack for the current thread. In this case, the call stack shows that the program is currently paused in the `main()` method.

![A screenshot of the Call Stack window showing the `main()` method.](Welcome.Cpp.Debugging.CallStack.png)

The [**Immediate**](vscmd://Debug.Immediate) window is a REPL (read-eval-print loop) that allows you to execute code at runtime. In this case, you can type *name* and press `Enter` to see the value of the `name` variable. You can also type *iteration* and press `Enter` to see the value of the `iteration` variable.

![A screenshot of the Immediate window showing the `name` and `iteration` variables.](Welcome.Cpp.Debugging.Immediate.png)

The [**Watch**](vscmd://Debug.Watch1) window allows you to define variables and expressions you want to track at run time. The window starts out empty, but you can add variables and expressions by clicking **Add item to watch**. In this screenshot, we're watching the `name` variable and the `name.size()` expression.

![A screenshot of the Watch window showing the `name` variable and the `name.size()` expression.](Welcome.Cpp.Debugging.Watch.png)

Select **Continue** to learn how to step through your code.
            ]]>
        </vst:Step.Description>
    </vst:Step>
    <vst:Step Title="Stepping through code"
        Id="Welcome.Cpp.Stepping">
        <vst:Step.Description>
            <![CDATA[
While stopped at a breakpoint, you can step through your code to see how it executes. There are three ways to step through your code:

- **Step into** {KeyboardShortcut:Debug.StepInto}: Step into the next statement, stepping into any method calls.
- **Step over** {KeyboardShortcut:Debug.StepOver}: Step over the next statement, stepping over any method calls.
- **Step out** {KeyboardShortcut:Debug.StepOut}: Step out of the current method.

Since you're already stopped on line 14, press {KeyboardShortcut:Debug.StepOver} to step over the `GetName` method call. The program will execute the `GetName` method on line 14, which blocks for user input. In the console app, enter your name and press `Enter` to continue.  Notice the execution then stops on line 15. 

If you revist the **Locals** window, you'll see that the `name` variable is now assigned a value. The `iteration` variable is still `1` because the loop hasn't completely executed yet.

You can continue stepping through the code line-by-line with {KeyboardShortcut:Debug.StepOver}. Remember to enter your name and press `Enter` when the program prompts you for input. Watch the variable values change in the **Locals** window.

![A screenshot of the Locals window showing the `name` and `iteration` variables.](Welcome.Cpp.Stepping.Locals.png)

After stepping through the loop a few times, press {KeyboardShortcut:Debug.Start} to **Continue** running the program. The program will run until it hits the breakpoint on line 14 again.

This time, instead of pressing {KeyboardShortcut:Debug.StepOver} to step over the `GetName` method call, press {KeyboardShortcut:Debug.StepInto} to **Step into** the method. Notice this time execution will stop inside the `GetName` method. Notice that the **Call Stack** window now shows that the program is stopped in the `GetName` method. 

![A screenshot of the Call Stack window showing the `GetName` method.](Welcome.Cpp.Stepping.CallStack.png)

Continue stepping through the code with {KeyboardShortcut:Debug.StepInto} and notice how the execution returns to the main program. Continue stepping with {KeyboardShortcut:Debug.StepInto} until you enter the `GetName` method again. This time, use {KeyboardShortcut:Debug.StepOut} to immediately step out of the `GetName` method.

End the program by selecting [**Debug** > **Stop Debugging**](vscmd://Debug.StopDebugging) {KeyboardShortcut:Debug.StopDebugging} from the menu bar or clicking the button on the toolbar.

- [Learn more about debugging](https://learn.microsoft.com/visualstudio/debugger/what-is-debugging)
- [Get a more in-depth look at debugging tools in Visual Studio](https://learn.microsoft.com/visualstudio/debugger/debugger-feature-tour)

Select **Continue** to take the next steps.

            ]]>
        </vst:Step.Description>
    </vst:Step>
    <vst:Step Title="Summary"
        Id="Welcome.Cpp.Summary">
        <vst:Step.Description>
            <![CDATA[
That's a brief introduction to editing and debugging C++ with Visual Studio! We've only scratched the surface of what Visual Studio can do. Here are some resources to help you learn more:

- [Visual Studio documentation](https://learn.microsoft.com/visualstudio/windows/)
- [Tutorial: Learn to debug C++ code using Visual Studio](https://learn.microsoft.com/en-us/visualstudio/debugger/getting-started-with-the-debugger-cpp)
- [Visual Studio on YouTube](https://www.youtube.com/visualstudio)
- [Microsoft C++, C, and Assembler documentation](https://learn.microsoft.com/cpp/)

Comments or suggestions for this guide? [Send us feedback](vscmd://Help.MyFeedback)!
            ]]>
        </vst:Step.Description>
    </vst:Step>
</vst:Guide>
