How good are the new C ++ tutorials

Creating a console computer in C ++

  • 19 minutes to read

C ++ programmers often start with a "Hello, World!" Application that is run from the command line. You can create such an application in Visual Studio using this article. Then, you'll deal with a slightly more difficult task: creating a calculator app.

requirements

Build your app project

Uses visual studio Projectsto organize code for an app, and Solutionsto organize your projects. A project contains all of the options, settings, and rules that you used to create your application. It also manages the relationships between all project files and external files. If you want to build your app, you must first create a new project and solution.

  1. When you start Visual Studio, the Visual Studio 2019 dialog box appears. click on Create a new project, to start.

    Alternatively, you can also use the menu bar in Visual Studio file > New > Project call. This will open the window Create a new project open.

  2. Select in the list of project templates Console app then click Further.

    Important

    Choose the C ++ version of the template Console app out. You can recognize this by the tags C ++ , Windows and console, and the symbol contains “++” in the corner.

  3. Click in the dialog box Configure a new project in the field Project name, and enter the name there CalculatorTutorial for the new project. Then click on Create.

    A blank C ++ Windows console application is created. Console applications use a Windows console window to display output and receive user input. An editor window opens in Visual Studio and the generated code is displayed:

Verify that your new app is built and running

The template for a new Windows console application creates a simple "Hello World" app in C ++. At this point, you can see how the apps you build right in the IDE are built and run in Visual Studio.

  1. To create your project, select from the menu Create the option Create a solution out. In the window output the result of the creation process is displayed.

  2. To run the code, click on the menu bar Debug > Start without debugging.

    A console window will open and your app will run. When you start a console app in Visual Studio, it runs your code and then prints "Press any key to close this window." . . ”(Press any key to continue) so that you can view the output. Congratulations! You've created your first Hello World! Console app in Visual Studio!

  3. Press a key to close the console window and return to Visual Studio.

You now have the tools to build and run your app after each change, to verify that the code still works as you'd expect. Later, I'll give you some debugging information if your code doesn't work.

Edit the code

Now convert the code in this template into a calculator app.

  1. Edit in the file CalculatorTutorial.cpp the code so that it looks like the following example:

    Understanding the code:

    • The statements allow you to reference code that is in other files. Sometimes you will see a filename enclosed in angle brackets ( <> ) is enclosed, sometimes it is enclosed in quotation marks ( " " ) locked in. Generally, angle brackets are used when referring to the C ++ standard library, while quotation marks are used for other files.
    • The line tells the compiler to expect this content from the C ++ standard library to be used in this file. Without this line, each keyword from the library would have to be placed in front of it in order to display its range. For example, without this line, any reference to as would have to be written. The statement is added to make the code clearer.
    • The keyword is used to make standard output in C ++. The operator << tells the compiler to send everything to the right of it to standard output.
    • The key word final is similar to the Enter key. It ends the line and lets the cursor jump to the next line. However, it has proven to be even more effective to use a -character within the character string with the same effect (including ""), since the buffer always empties and can damage the performance of the program. Since this is a small app, it is used instead for reasons of readability.
    • All C ++ statements must end with a semicolon, and all C ++ applications must contain a function. This function is carried out by the program first. The function must have access to all of the code so that it can be used.
  2. If you want to save the file, press CTRL + S, or click the at the top of the IDE to saveSymbol: the diskette symbol in the toolbar below the menu bar.

  3. Press CTRL + F5to run the application or switch to the DebugMenu and select from there Start without debugging out. A console window should now appear with the text specified in the code.

  4. Once you're done, close the console window.

Adding code for calculations

Now you're ready to add math logic.

Adding a machine class

  1. Go to the menu Project, and choose Add class out. In the input field for Class name the name Calculator (Calculator). click on OK. Two new files are added to your project. To save all changed files at once, press CTRL + SHIFT + S. This is the keyboard shortcut for file > Save all. There is also a toolbar button for Save all: an icon with two floppy disks. This button is next to the button to save. In general, it has proven useful Save all frequently to ensure that all files are actually saved.

    A class is like a design for an object that does something. In this case, a computer and its functionality should be defined. The assistant Add classyou used above created .h and .cpp files that have the same name as the class. In the window displayed at the edge of the IDE Solution Explorer you can view a full list of your project files. If the window is not displayed, you can open it from the menu bar: Click on view > Solution Explorer.

    You should now have three tabs open in Notepad: CalculatorTutorial.cpp, Calculator.h and Calculator.cpp. If you accidentally close one of these, you can save it in the Solution Explorer-Open the window again with a double click on the file.

  2. Remove in Calculator.h however, the lines and that were created are not needed. Then add the following line of code so that the file now looks like this:

    Understanding the code

    • The line you added declares a new function called that you use to perform math operations for addition, subtraction, multiplication, and division.
    • C ++ code is divided into Header files (.dog Source files (.cpp). Different file extensions are also supported by different compilers; but the ones just presented are the most important ones that you should know. Functions and variables are normally used declared, d. H. they are assigned a name and type in the header files, and implemented, d. H. a definition is assigned to them in the source files. You can use to access code defined in another file. Where "filename.h" is the name of the file that declares the variables and functions that you want to use.
    • The two lines you deleted have one Constructor and one Destructor declared for the class. For a simple class like this one, the compiler creates these for you. However, their use is outside the scope covered in this tutorial.
    • It is a good practice to organize your code into different files based on what you do. This makes it easier to find the code you need later. Here you define the class and the file containing the function individually. However, reference should still be made to the class.
  3. A green wavy line appears below. This is because the function has not been defined in the CPP file. Hover over the word, click the screwdriver that appears, then click Create definition of 'Calculate' in Calculator.cpp (Create definition of "Calculate" in Calculator.cpp).

    A pop-up item will appear showing you a preview of the code change that was made in the other file. The code was Calculator.cpp added.

    Currently only 0.0 is returned. Change that now. Press ESCto close the pop-up item.

  4. Switch to Calculator.cppFile in the editor window. Remove the areas and (as already done in the .h file) and add the following code:

    Understanding the code

    • The function takes a number, an operator, and a second number, and then performs the requested operation on the specified numbers.
    • The switch statement checks which operator has been provided and only executes the case appropriate for that operation. The "default:" case is a fallback if the user enters an operator that is not accepted so that the program is not interrupted. In general, invalid user input is best handled in a more elegant way. However, this would lead too far for this tutorial.
    • The keyword indicates a type of number that supports decimal numbers. In this way, the calculator can handle calculations involving both decimal numbers and whole numbers. The function must always return such a number because of the very beginning of the code (this specifies the return type of the function). Therefore "0.0" is returned in the standard case.
    • The .h file declares the function prototypewhich tells the compiler in advance which parameter is required and which return type is to be expected. All implementation details of the function are contained in the .cpp file.

Now if you write and run the code again, it will exit again when prompted for what you want to do. Next, edit the function to do some calculations.

Calling the member functions of the computer class

  1. Now update the function in CalculatorTutorial.cpp:

    Understanding the code

    • Since C ++ programs always start with the function, you have to call the other code from there. So an instruction is required.
    • Some initial variables (,, and) are declared to store the first number, the second number, the operator, and the final result, respectively. It is always a good idea to include some initial variables to avoid undefined behavior. This is exactly what happened here.
    • The line declares an object named “c” as an instance of the class. The class itself is just a blueprint for how the calculator works. The object is the specific computer that does the calculations.
    • The statement is a loop. The code inside the loop is executed again and again until the condition inside the is met. Since the condition is only listed as, it is always true, so the loop will run continuously. To close the program, the user must manually close the console window. Otherwise the program constantly waits for a new entry.
    • The keyword is used to accept user input. This input stream is intelligent enough to process a line of text entered in the console window and place it in the correct order within all of the listed variables, provided that user input meets the required specifications. You can edit this line to accept different types of input, such as: B. more than two numbers. But the function would also have to be updated for this.
    • The expression calls the previously defined function and provides the input values ​​entered. The function then returns a number that is stored in.
    • Finally, there is output in the console so that the user can view the result of the calculation.

Rebuilding and testing the code

Now test the program again to make sure everything works as intended.

  1. Press CTRL + F5to rebuild and start the app.

  2. Enter and press ENTER. Check if the result is 10.

Debug the app

Since there are no restrictions on what the user can type in the console window, make sure that the calculator processes input as expected. Instead of running the program, you debug it so you can see exactly how the program works, step by step.

Run the app in the debugger

  1. Set a breakpoint on the line exactly after the point at which the user was prompted for input. To set the breakpoint, click on the gray, vertical border next to the line on the left side of the editor window. A red dot is displayed.

    From now on, execution will always stop at this line when you debug the program. We already have a rough idea that the program will work in simple cases. Since we don't want to stop execution every time, we set the breakpoint as conditional.

  2. Right-click the red dot that represents the breakpoint, then select conditions out. Enter in the input field for the condition. When you're done, choose the button OK out. The condition is saved automatically.

    The execution is stopped at the breakpoint exactly when an attempt is made to divide by 0.

  3. Press F5to debug the program or select the button Windows local debugger with the green arrow icon on the toolbar. For example, if you are in your console app. If you enter "5 - 0", for example, the program behaves normally and continues to run. However, if you now enter “10/0”, the program will stop at the breakpoint. Even putting any number of spaces between the operator and the numbers is smart enough to parse the input correctly.

Useful windows in the debugger

Once you debug your code, you can find that a couple of new windows pop up. These windows help you debug. Look at the window automobile at. In the window automobile you can see the current values ​​of the variables that were used in at least the last three lines and up to the current line. If you want to see all the variables of this function, switch to the window Local. In fact, you can edit the values ​​of these variables while debugging to see what effect they would have on the program. However, you do not edit the variables here.

You can also simply move the mouse pointer over variables directly in the code to display their current values ​​at the points at which execution was paused. Make sure the editor window is in the foreground by clicking it before testing this process.

Continue debugging

  1. The current status of the execution is displayed in the yellow line on the left. The current line calls. So press F11to get one Single step to perform in the function. This takes you to the text of the function. Apply the Single step wisely; if you do this too often you can waste a lot of time. This takes you into any code you use on the line, including the standard library functions.

  2. The execution status is now at the beginning of the function. Press F10to move to the next line in the program execution. F10 is also known as Procedural step designated. You can choose the option Skip Use to jump from line to line without looking at the details of each part of the line. In principle, you should Skip across from Jump in unless you really want to take a closer look at the code retrieved from another point, like you did to look at the body of.

  3. use F10to keep lines too long skipuntil you are back in the function in the other file and stop there on the line.

    It seems the program works as expected: it takes the first number and divides it by the second. Move the mouse pointer over the variable in the line or see yourself in the window automobile at. You can see that the value is listed as "inf" which is apparently wrong, so let's fix this. The line only outputs whatever value is stored in. So if you are using F10 jump one line further, the following is displayed in the console window:

    This result is because division by zero (0) is not defined. So the program does not have a numeric response for the requested operation.

Fixing the "Division by zero" error

Develop a more elegant solution to division by zero so that the user understands the problem.

  1. Take in CalculatorTutorial.cpp make the following changes. Thanks to a debugger feature called Edit and continue the program can continue to run while you make changes:

  2. Now press once F5. Program execution continues properly until the program pauses to request user input. Please enter again. A more helpful answer will now be given. The user will be prompted for further input and the program will continue to run normally.

    Note

    Editing code while the program is in debug mode runs the risk of making the code out of date. This happens when the debugger is still running your old code and your changes have not yet been applied. In such a case you will be informed by a popup message from the debugger. Occasionally you should F5 Press to update the code that was just running. In particular, if you make a change in a function while the execution point is within that exact function, you must take a procedural step from that function and then jump back into the function to get the updated code. If for whatever reason this doesn't work and an error message is returned, you can stop debugging by clicking the red square on the toolbar under the menus at the top of the IDE, then debug using F5 start again, or click on the green play arrow in the toolbar next to the stop button.

    Understand the keyboard shortcuts for running and debugging

    • F5 or. Debug > Start debugging starts a debugging session if none is active and runs the program until a breakpoint is reached or the program requires user input. If no user input is required and there is no breakpoint to be reached, the program exits and the console window closes automatically once the program has finished executing. If you want to run a "Hello World" or similar program, use CTRL + F5 or set a breakpoint before you F5 Press so that the window does not close.
    • With CTRL + F5 or. Debug > Start without debugging the application runs without entering debug mode. This takes a little less time than debugging, and the console window stays open after the program finishes running.
    • F10 or. Skip allows you to step through the code line by line, which gives you an idea of ​​how the code is executing and what variable values ​​there are at each execution step.
    • F11 or. Jump in works similarly to Skip. However, a jump is made to every function that is called on the respective execution line. If the line being executed e.g. B. calls a function, leaves F11 move the pointer into the body of that function so you can follow the function code that ran before returning to the line where you pressed F11. If you F10 pressing, function calls are simply skipped and the pointer simply advances to the next line. The function call still takes place, but the program does not pause so that you can see what it is doing.

Close the app

  • If it has not finished running, close the console window for the Calculator app.

The finished app

Congratulations! You have completed the code for the calculator app, built and debugged it in Visual Studio.

Next Steps

More information about Visual Studio for C ++

C ++ programmers often start with a "Hello, World!" Application that is run from the command line. You can create such an application in Visual Studio using this article. Then, you'll deal with a slightly more difficult task: creating a calculator app.

requirements

Build your app project

Uses visual studio Projectsto organize code for an app, and Solutionsto organize your projects. A project contains all of the options, settings, and rules that you used to create your application. It also manages the relationships between all project files and external files. If you want to build your app, you must first create a new project and solution.

  1. On the menu bar in Visual Studio, click file > New > Project. The window New project is displayed.

  2. Check the left sidebar to see if Visual C ++ is selected. Select in the middle area Windows console application out.

  3. Enter below in the input field Surname the term CalculatorTutorial as the name for the new project, and then click OK.

    A blank C ++ Windows console application is created. Console applications use a Windows console window to display output and receive user input. An editor window opens in Visual Studio and the generated code is displayed:

Verify that your new app is built and running

The template for a new Windows console application creates a simple C ++ "Hello World" app. At this point, you can see how the apps you build right in the IDE are built and run in Visual Studio.

  1. To create your project, select from the menu Create the option Create a solution out. In the window output the result of the creation process is displayed.

  2. To run the code, click on the menu bar Debug > Start without debugging.

    A console window will open and your app will run. When you start a console app in Visual Studio, it runs your code and then says “Press any key to continue. . ”(Press any key to continue) so that you can view the output. Congratulations! You've created your first Hello World! Console app in Visual Studio!

  3. Press a key to close the console window and return to Visual Studio.

You now have the tools to build and run your app after each change, to verify that the code still works as you'd expect. Later, I'll give you some debugging information if your code doesn't work.

Edit the code

Now convert the code in this template into a calculator app.

  1. Edit in the file CalculatorTutorial.cpp the code so that it looks like the following example:

    Understanding the code:

    • The statements allow you to reference code that is in other files. Sometimes you will see a filename enclosed in angle brackets ( <> ) is enclosed, sometimes it is enclosed in quotation marks ( " " ) locked in. Generally, angle brackets are used when referring to the C ++ standard library, while quotation marks are used for other files.
    • The line (or line in Visual Studio 2017 and earlier) refers to something called a precompiled header. These are often used by professional programmers to improve compilation times. For this tutorial, that would be too far-reaching.
    • The line tells the compiler to expect this content from the C ++ standard library to be used in this file. Without this line, each keyword from the library would have to be placed in front of it in order to display its range. For example, without this line, any reference to as would have to be written. The statement is added to make the code clearer.
    • The keyword is used to make standard output in C ++. The operator << tells the compiler to send everything to the right of it to standard output.
    • The key word final is similar to the Enter key. It ends the line and lets the cursor jump to the next line. However, it has proven to be even more effective to use a -character within the character string with the same effect (including ""), since the buffer always empties and can damage the performance of the program. Since this is a small app, it is used instead for reasons of readability.
    • All C ++ statements must end with a semicolon, and all C ++ applications must contain a function. This function is carried out by the program first. The function must have access to all of the code so that it can be used.
  2. If you want to save the file, press CTRL + S, or click the at the top of the IDE to saveSymbol: the diskette symbol in the toolbar below the menu bar.

  3. Press CTRL + F5to run the application or switch to the DebugMenu and select from there Start without debugging out. If there is a popup item with the message This project is out of date is displayed, you can Don't show this dialog again select, and then Yesto build your application. A console window should now appear with the text specified in the code.

  4. Once you're done, close the console window.

Adding code for calculations

Now you're ready to add math logic.

Adding a machine class

  1. Go to the menu Project, and choose Add class out. In the input field for Class name the name Calculator (Calculator). click on OK. Two new files are added to your project. To save all changed files at once, press CTRL + SHIFT + S. This is the keyboard shortcut for file > Save all. There is also a toolbar button for Save all: an icon with two floppy disks. This button is next to the button to save. In general, it has proven useful Save all frequently to ensure that all files are actually saved.

    A class is like a design for an object that does something. In this case, a computer and its functionality should be defined. The assistant Add classyou used above created .h and .cpp files that have the same name as the class. In the window displayed at the edge of the IDE Solution Explorer you can view a full list of your project files. If the window is not displayed, you can open it from the menu bar: Click on view > Solution Explorer.

    You should now have three tabs open in Notepad: CalculatorTutorial.cpp, Calculator.h and Calculator.cpp. If you accidentally close one of these, you can save it in the Solution Explorer-Open the window again with a double click on the file.

  2. Remove in Calculator.h however, the lines and that were created are not needed. Then add the following line of code so that the file now looks like this:

    Understanding the code

    • The line you added declares a new function called that you use to perform math operations for addition, subtraction, multiplication, and division.
    • C ++ code is divided into Header files (.dog Source files (.cpp). Different file extensions are also supported by different compilers; but the ones just presented are the most important ones that you should know. Functions and variables are normally used declared, d. H. they are assigned a name and type in the header files, and implemented, d. H. a definition is assigned to them in the source files. You can use to access code defined in another file. Where "filename.h" is the name of the file that declares the variables and functions that you want to use.
    • The two lines you deleted have one Constructor and one Destructor declared for the class. For a simple class like this one, the compiler creates these for you. However, their use is outside the scope covered in this tutorial.
    • It is a good practice to organize your code into different files based on what you do. This makes it easier to find the code you need later. Here you define the class and the file containing the function individually. However, reference should still be made to the class.
  3. A green wavy line appears below. This is because the function has not been defined in the CPP file. Hover over the word, then click the lightbulb that appears, then select Create definition of "Calculate" in Calculator.cpp (Create definition of "Calculate" in Calculator.cpp). A pop-up item will appear showing you a preview of the code change that was made in the other file. The code was Calculator.cpp added.

    Currently only 0.0 is returned. Change that now. Press ESCto close the pop-up item.

  4. Switch to Calculator.cppFile in the editor window. Remove the areas and (as already done in the .h file) and add the following code:

    Understanding the code

    • The function takes a number, an operator, and a second number, and then performs the requested operation on the specified numbers.
    • The switch statement checks which operator has been provided and only executes the case appropriate for that operation. The "default:" case is a fallback if the user enters an operator that is not accepted so that the program is not interrupted. In general, invalid user input is best handled in a more elegant way. However, this would lead too far for this tutorial.
    • The keyword indicates a type of number that supports decimal numbers. In this way, the calculator can handle calculations involving both decimal numbers and whole numbers. The function must always return such a number because of the very beginning of the code (this specifies the return type of the function). Therefore "0.0" is returned in the standard case.
    • The .h file declares the function prototypewhich tells the compiler in advance which parameter is required and which return type is to be expected. All implementation details of the function are contained in the .cpp file.

Now if you write and run the code again, it will exit again when prompted for what you want to do. Next, edit the function to do some calculations.

Calling the member functions of the computer class

  1. Now update the function in CalculatorTutorial.cpp:

    Understanding the code

    • Since C ++ programs always start with the function, you have to call the other code from there. So an instruction is required.
    • Some initial variables (,, and) are declared to store the first number, the second number, the operator, and the final result, respectively. It is always a good idea to include some initial variables to avoid undefined behavior. This is exactly what happened here.
    • The line declares an object named “c” as an instance of the class.The class itself is just a blueprint for how the calculator works. The object is the specific computer that does the calculations.
    • The statement is a loop. The code inside the loop is executed again and again until the condition inside the is met. Since the condition is only listed as, it is always true, so the loop will run continuously. To close the program, the user must manually close the console window. Otherwise the program constantly waits for a new entry.
    • The keyword is used to accept user input. This input stream is intelligent enough to process a line of text entered in the console window and place it in the correct order within all of the listed variables, provided that user input meets the required specifications. You can edit this line to accept different types of input, such as: B. more than two numbers. But the function would also have to be updated for this.
    • The expression calls the previously defined function and provides the input values ​​entered. The function then returns a number that is stored in.
    • Finally, there is output in the console so that the user can view the result of the calculation.

Rebuilding and testing the code

Now test the program again to make sure everything works as intended.

  1. Press CTRL + F5to rebuild and start the app.

  2. Enter and press ENTER. Check if the result is 10.

Debug the app

Since there are no restrictions on what the user can type in the console window, make sure that the calculator processes input as expected. Instead of running the program, you debug it so you can see exactly how the program works, step by step.

Run the app in the debugger

  1. Set a breakpoint on the line exactly after the point at which the user was prompted for input. To set the breakpoint, click on the gray, vertical border next to the line on the left side of the editor window. A red dot is displayed.

    From now on, execution will always stop at this line when you debug the program. We already have a rough idea that the program will work in simple cases. Since we don't want to stop execution every time, we set the breakpoint as conditional.

  2. Right-click the red dot that represents the breakpoint, then select conditions out. Enter in the input field for the condition. When you're done, choose the button OK out. The condition is saved automatically.

    The execution is stopped at the breakpoint exactly when an attempt is made to divide by 0.

  3. Press F5to debug the program or select the button Windows local debugger with the green arrow icon on the toolbar. For example, if you are in your console app. If you enter "5 - 0", for example, the program behaves normally and continues to run. However, if you now enter “10/0”, the program will stop at the breakpoint. Placing any number of spaces between the operator and the numbers is smart enough to still parse the input correctly.

Useful windows in the debugger

Once you debug your code, you can find that a couple of new windows pop up. These windows help you debug. Look at the window automobile at. In the window automobile you can see the current values ​​of the variables that were used in at least the last three lines and up to the current line.

If you want to see all the variables of this function, switch to the window Local. In fact, you can edit the values ​​of these variables while debugging to see what effect they would have on the program. However, you do not edit the variables here.

You can also simply move the mouse pointer over variables directly in the code to display their current values ​​at the points at which execution was paused. Make sure the editor window is in the foreground by clicking it before testing this process.

Continue debugging

  1. The current status of the execution is displayed in the yellow line on the left. The current line calls. So press F11to get one Single step to perform in the function. This takes you to the text of the function. Apply the Single step wisely; if you do this too often you can waste a lot of time. This takes you into any code you use on the line, including the standard library functions.

  2. The execution status is now at the beginning of the function. Press F10to move to the next line in the program execution. F10 is also known as Procedural step designated. You can choose the option Skip Use to jump from line to line without looking at the details of each part of the line. In principle, you should Skip across from Jump in unless you really want to take a closer look at the code retrieved from another point, like you did to look at the body of.

  3. use F10to keep lines too long skipuntil you are back in the function in the other file and stop there on the line.

    It seems the program works as expected: it takes the first number and divides it by the second. Move the mouse pointer over the variable in the line or see yourself in the window automobile at. You can see that the value is listed as "inf" which is apparently wrong, so let's fix this. The line only outputs whatever value is stored in. So if you are using F10 jump one line further, the following is displayed in the console window:

    This result is because division by zero (0) is not defined. So the program does not have a numeric response for the requested operation.

Fixing the "Division by zero" error

Develop a more elegant solution to division by zero so that the user understands the problem.

  1. Take in CalculatorTutorial.cpp make the following changes. Thanks to a debugger feature called Edit and continue the program can continue to run while you make changes:

  2. Now press once F5. Program execution continues properly until the program pauses to request user input. Please enter again. A more helpful answer will now be given. The user will be prompted for further input and the program will continue to run normally.

    Note

    Editing code while the program is in debug mode runs the risk of making the code out of date. This happens when the debugger is still running your old code and your changes have not yet been applied. In such a case you will be informed by a popup message from the debugger. Occasionally you should F5 Press to update the code that was just running. In particular, if you make a change in a function while the execution point is within that exact function, you must take a procedural step from that function and then jump back into the function to get the updated code. If for whatever reason this doesn't work and an error message is returned, you can stop debugging by clicking the red square on the toolbar under the menus at the top of the IDE, then debug using F5 start again, or click on the green play arrow in the toolbar next to the stop button.

    Understand the keyboard shortcuts for running and debugging

    • F5 or. Debug > Start debugging starts a debugging session if none is active and runs the program until a breakpoint is reached or the program requires user input. If no user input is required and there is no breakpoint to be reached, the program exits and the console window closes automatically once the program has finished executing. If you want to run a "Hello World" or similar program, use CTRL + F5 or set a breakpoint before you F5 Press so that the window does not close.
    • With CTRL + F5 or. Debug > Start without debugging the application runs without entering debug mode. This takes a little less time than debugging, and the console window stays open after the program finishes running.
    • F10 or. Skip allows you to step through the code line by line, which gives you an idea of ​​how the code is executing and what variable values ​​there are at each execution step.
    • F11 or. Jump in works similarly to Skip. However, a jump is made to every function that is called on the respective execution line. If the line being executed e.g. B. calls a function, leaves F11 move the pointer into the body of that function so you can follow the function code that ran before returning to the line where you pressed F11. If you F10 pressing, function calls are simply skipped and the pointer simply advances to the next line. The function call still takes place, but the program does not pause so that you can see what it is doing.

Close the app

  • If it has not finished running, close the console window for the Calculator app.

The finished app

Congratulations! You have completed the code for the calculator app, built and debugged it in Visual Studio.

Next Steps

More information about Visual Studio for C ++

Is this page helpful?