Skip to content

Commit 1ab8b2d

Browse files
author
Colin Robertson
committed
Don't build the includes separately.
1 parent 727a783 commit 1ab8b2d

28 files changed

Lines changed: 30 additions & 25 deletions

docs/docfx.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"group": "group-vc2015",
1010
"src": ".",
1111
"exclude": [
12+
"**/2019/**",
13+
"**/2017/**",
1214
"**/obj/**",
1315
"vcppdocs/**",
1416
"**/includes/**"

docs/get-started/2019/tutorial-console-cpp.md

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,35 @@ The usual starting point for a C++ programmer is a "Hello, world!" application t
1919

2020
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 also manages the relationship between all the project's files and any external files. To create your app, first, you'll create a new project and solution.
2121

22-
1. On the menubar in Visual Studio, choose **File** > **New** > **Project**. The **New Project** window opens.
22+
1. On the menubar in Visual Studio, choose **File** > **New** > **Project**. The **Create a new project** window opens.
2323

24-
2. On the left sidebar, make sure **Visual C++** is selected. In the center, choose **Windows Console Application**.
24+
![The Create a new project dialog](./2019/media/calculator-new-project-dialog.png "The Create a new project dialog")
2525

26-
3. In the **Name** edit box at the bottom, name the new project *CalculatorTutorial*, then choose **OK**.
26+
2. In the list of project templates, choose **Console App**, then choose **Next**.
2727

28-
![The New Project dialog](./media/calculator-new-project-dialog.png "The New Project dialog")
28+
![Choose the Console App template](./2019/media/calculator-new-project-dialog.png "Choose the Console App template")
29+
30+
3. In the **Configure your new project** dialog box, select the **Project name** edit box, name your new project *CalculatorTutorial*, then choose **Create**.
31+
32+
![Name your project in the Configure your new project dialog](./2019/media/calculator-new-project-dialog.png "Name your project in the Configure your new project dialog")
2933

3034
An empty C++ Windows console application gets created. Console applications use a Windows console window to display output and accept user input. In Visual Studio, an editor window opens and shows the generated code:
3135

3236
```cpp
3337
// CalculatorTutorial.cpp : This file contains the 'main' function. Program execution begins and ends there.
3438
//
3539

36-
#include "pch.h"
3740
#include <iostream>
3841

3942
int main()
4043
{
41-
std::cout << "Hello World!\n";
44+
std::cout << "Hello World!\n";
4245
}
4346

4447
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
4548
// Debug program: F5 or Debug > Start Debugging menu
4649

47-
// Tips for Getting Started:
50+
// Tips for Getting Started:
4851
// 1. Use the Solution Explorer window to add/manage files
4952
// 2. Use the Team Explorer window to connect to source control
5053
// 3. Use the Output window to see build output and other messages
@@ -55,15 +58,15 @@ Visual Studio uses *projects* to organize the code for an app, and *solutions* t
5558

5659
## Verify that your new app builds and runs
5760

58-
The template for a new windows console application creates a simple C++ "Hello World" app. At this point, you can see how Visual Studio builds and runs the apps you create right from the IDE.
61+
The template for a new Windows console application creates a simple C++ "Hello World" app. At this point, you can see how Visual Studio builds and runs the apps you create right from the IDE.
5962

6063
1. To build your project, choose **Build Solution** from the **Build** menu. The **Output** window shows the results of the build process.
6164

62-
![Build the project](./media/calculator-initial-build-output.png "Build the project")
65+
![Build the project](./2019/media/calculator-initial-build-output.png "Build the project")
6366

6467
1. To run the code, on the menu bar, choose **Debug**, **Start without debugging**.
6568

66-
![Start the project](./media/calculator-hello-world-console.png "Start the project")
69+
![Start the project](./2019/media/calculator-hello-world-console.png "Start the project")
6770

6871
A console window opens and then runs your app. When you start a console app in Visual Studio, it runs your code, then prints "Press any key to continue . . ." to give you a chance to see the output. Congratulations! You've created your first "Hello, world!" console app in Visual Studio!
6972

@@ -118,7 +121,7 @@ Now let's turn the code in this template into a calculator app.
118121

119122
1. To run the application, press **Ctrl+F5** or go to the **Debug** menu and choose **Start Without Debugging**. If you get a pop-up that says **This project is out of date**, you may select **Do not show this dialog again**, and then choose **Yes** to build your application. You should see a console window appear that displays the text specified in the code.
120123

121-
![Build and start your application](./media/calculator-first-launch.gif "Build and start your application")
124+
![Build and start your application](./2019/media/calculator-first-launch.gif "Build and start your application")
122125

123126
1. Close the console window when you're done.
124127

@@ -130,11 +133,11 @@ It's time to add some math logic.
130133

131134
1. Go to the **Project** menu and choose **Add Class**. In the **Class Name** edit box, enter *Calculator*. Choose **OK**. Two new files get added to your project. To save all your changed files at once, press **Ctrl+Shift+S**. It's a keyboard shortcut for **File** > **Save All**. There's also a toolbar button for **Save All**, an icon of two floppy disks, found beside the **Save** button. In general, it's good practice to do **Save All** frequently, so you don't miss any files when you save.
132135

133-
![Create the Calculator class](./media/calculator-create-class.gif "Create the Calculator class")
136+
![Create the Calculator class](./2019/media/calculator-create-class.gif "Create the Calculator class")
134137

135138
A class is like a blueprint for an object that does something. In this case, we define a calculator and how it should work. The **Add Class** wizard you used above created .h and .cpp files that have the same name as the class. You can see a full list of your project files in the **Solution Explorer** window, visible on the side of the IDE. If the window isn't visible, you can open it from the menu bar: choose **View** > **Solution Explorer**.
136139

137-
![Solution Explorer](./media/calculator-solution-explorer.png "Solution Explorer")
140+
![Solution Explorer](./2019/media/calculator-solution-explorer.png "Solution Explorer")
138141

139142
You should now have three tabs open in the editor: *CalculatorTutorial.cpp*, *Calculator.h*, and *Calculator.cpp*. If you accidentally close one of them, you can reopen it by double-clicking it in the **Solution Explorer** window.
140143

@@ -158,7 +161,7 @@ It's time to add some math logic.
158161
159162
1. You'll see a green squiggle appear under `Calculate`. It's because we haven't defined the `Calculate` function in the .cpp file. Hover over the word, click the lightbulb that pops up, and choose **Create definition of 'Calculate' in Calculator.cpp**. A pop-up appears that gives you a peek of the code change that was made in the other file. The code was added to *Calculator.cpp*.
160163

161-
![Create definition of Calculate](./media/calculator-create-definition.gif "Create definition of Calculate")
164+
![Create definition of Calculate](./2019/media/calculator-create-definition.gif "Create definition of Calculate")
162165

163166
Currently, it just returns 0.0. Let's change that. Press **Esc** to close the pop-up.
164167

@@ -250,7 +253,7 @@ Now it's time to test the program again to make sure everything works properly.
250253

251254
1. Enter `5 + 5`, and press **Enter**. Verify that the result is 10.
252255

253-
![The result of 5 + 5](./media/calculator-five-plus-five.png "The result of 5 + 5")
256+
![The result of 5 + 5](./2019/media/calculator-five-plus-five.png "The result of 5 + 5")
254257

255258
## Debug the app
256259

@@ -260,33 +263,33 @@ Since the user is free to type anything into the console window, let's make sure
260263

261264
1. Set a breakpoint on the `result = c.Calculate(x, oper, y);` line, just after the user was asked for input. To set the breakpoint, click next to the line in the gray vertical bar along the left edge of the editor window. A red dot appears.
262265

263-
![Set a breakpoint](./media/calculator-set-breakpoint.gif "Set a breakpoint")
266+
![Set a breakpoint](./2019/media/calculator-set-breakpoint.gif "Set a breakpoint")
264267

265268
Now when we debug the program, it always pauses execution at that line. We already have a rough idea that the program works for simple cases. Since we don't want to pause execution every time, let's make the breakpoint conditional.
266269

267270
1. Right-click the red dot that represents the breakpoint, and choose **Conditions**. In the edit box for the condition, enter `(y == 0) && (oper == '/')`. Choose the **Close** button when you're done. The condition is saved automatically.
268271

269-
![Set a conditional breakpoint](./media/calculator-conditional-breakpoint.gif "Set a conditional breakpoint")
272+
![Set a conditional breakpoint](./2019/media/calculator-conditional-breakpoint.gif "Set a conditional breakpoint")
270273

271274
Now we pause execution at the breakpoint specifically if a division by 0 is attempted.
272275

273276
1. To debug the program, press **F5**, or choose the **Local Windows Debugger** toolbar button that has the green arrow icon. In your console app, if you enter something like "5 - 0", the program behaves normally and keeps running. However, if you type "10 / 0", it pauses at the breakpoint. You can even put any number of spaces between the operator and numbers; `cin` is smart enough to parse the input appropriately.
274277

275-
![Pause at the conditional breakpoint](./media/calculator-debug-conditional.gif "Pause at the conditional breakpoint")
278+
![Pause at the conditional breakpoint](./2019/media/calculator-debug-conditional.gif "Pause at the conditional breakpoint")
276279

277280
### Useful windows in the debugger
278281

279282
Whenever you debug your code, you may notice that some new windows appear. These windows can assist your debugging experience. Take a look at the **Autos** window. The **Autos** window shows you the current values of variables used at least three lines before and up to the current line.
280283

281-
![The Autos window](./media/calculator-autos.png "The Autos window")
284+
![The Autos window](./2019/media/calculator-autos.png "The Autos window")
282285

283286
To see all of the variables from that function, switch to the **Locals** window. You can actually modify the values of these variables while debugging, to see what effect they would have on the program. In this case, we'll leave them alone.
284287

285-
![The Locals window](./media/calculator-locals.png "The Locals window")
288+
![The Locals window](./2019/media/calculator-locals.png "The Locals window")
286289

287290
You can also just hover over variables in the code itself to see their current values where the execution is currently paused. Make sure the editor window is in focus by clicking on it first.
288291

289-
![Hover to view current variable values](./media/calculator-hover-tooltip.gif "Hover to view current variable values")
292+
![Hover to view current variable values](./2019/media/calculator-hover-tooltip.gif "Hover to view current variable values")
290293

291294
### To continue debugging
292295

@@ -296,11 +299,11 @@ You can also just hover over variables in the code itself to see their current v
296299

297300
1. Continue using **F10** to **Step Over** each line until you get back to the `main()` function in the other file, and stop on the `cout` line.
298301

299-
![Step out of Calculate and check result](./media/calculator-undefined-zero.gif "Step out of Calculate and check result")
302+
![Step out of Calculate and check result](./2019/media/calculator-undefined-zero.gif "Step out of Calculate and check result")
300303

301304
1. It looks like the program is doing what is expected: it takes the first number, and divides it by the second. On the `cout` line, hover over the `result` variable or take a look at `result` in the **Autos** window. You'll see its value is listed as "inf", which doesn't look right, so let's fix it. The `cout` line just outputs whatever value is stored in `result`, so when you step one more line forward using **F10**, the console window displays:
302305

303-
![The result of divide by zero](./media/calculator-divide-by-zero-fail.png "The result of divide by zero")
306+
![The result of divide by zero](./2019/media/calculator-divide-by-zero-fail.png "The result of divide by zero")
304307

305308
This result happens because division by zero is undefined, so the program doesn't have a numerical answer to the requested operation.
306309

@@ -352,7 +355,7 @@ Let's handle division by zero more gracefully, so a user can understand the prob
352355

353356
1. Now press **F5** once. Program execution continues all the way until it has to pause to ask for user input. Enter `10 / 0` again. Now, a more helpful message is printed. The user is asked for more input, and the program continues executing normally.
354357

355-
![The final result after changes](./media/calculator-final-verification.gif "The final result after changes")
358+
![The final result after changes](./2019/media/calculator-final-verification.gif "The final result after changes")
356359

357360
> ![Note]
358361
> When you edit code while in debugging mode, there is a risk of code becoming stale. This happens when the debugger is still running your old code, and has not yet updated it with your changes. The debugger pops up a dialog to inform you when this happens. Sometimes, you may need to press **F5** to refresh the code being executed. In particular, if you make a change inside a function while the point of execution is inside that function, you'll need to step out of the function, then back into it again to get the updated code. If that doesn't work for some reason and you see an error message, you can stop debugging by clicking on the red square in the toolbar under the menus at the top of the IDE, then start debugging again by entering **F5** or by choosing the green "play" arrow beside the stop button on the toolbar.
@@ -372,7 +375,7 @@ Let's handle division by zero more gracefully, so a user can understand the prob
372375

373376
Congratulations! You've completed the code for the calculator app, and built and debugged it in Visual Studio.
374377

375-
![Calculator console application](./media/calculator-app.gif "Calculator console application")
378+
![Calculator console application](./2019/media/calculator-app.gif "Calculator console application")
376379

377380
## Next steps
378381

-15.1 KB
Binary file not shown.
-6.78 KB
Binary file not shown.
-127 KB
Binary file not shown.
-154 KB
Binary file not shown.
-80.6 KB
Binary file not shown.
-357 KB
Binary file not shown.
-8.17 KB
Binary file not shown.
-58.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)