{"id":15255,"date":"2017-04-21T20:45:28","date_gmt":"2017-04-21T20:45:28","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=15255"},"modified":"2020-12-09T17:06:06","modified_gmt":"2020-12-09T17:06:06","slug":"getting-started-with-visual-studio-for-c-and-cpp-development","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/getting-started-with-visual-studio-for-c-and-cpp-development\/","title":{"rendered":"Getting Started with Visual Studio for C and C++ Development"},"content":{"rendered":"<p>Are you new to Visual Studio and working with C++? Then you\u2019ve come to the right place. Whether you\u2019re a student writing one of your first programs or a seasoned C++ developer with years of experience, you&#8217;ll find Visual Studio to be a powerful environment for C++ development. Visual Studio is an IDE packed with features, from code browsing, colorization and navigation, to autocompletion of symbols, a built-in compiler and build system, a top of the line debugger, and built-in testing and code analysis tools. We have you covered from beginning to end, from code inception to continuous integration management, but of course this means there is a lot to learn. This blog post breaks down the basics to get you started. You will get only a small glimpse of the powerful tools that Visual Studio provides, but if you want to learn more, you should click the links throughout this post.<\/p>\n<p>This blog post goes over the following concepts:<\/p>\n<ol>\n<li><a href=\"#Setup\">Setting Up Visual Studio<\/a><\/li>\n<li><a href=\"#Opening\">Opening Projects or Folders of Code<\/a><\/li>\n<li><a href=\"#Building\">Building the Application<\/a><\/li>\n<li><a href=\"#EditAndNav\">Code Editing &amp; Navigation<\/a><\/li>\n<li><a href=\"#Debug\">Debugging and Diagnosing Issues<\/a><\/li>\n<li><a href=\"#Testing\">Testing<\/a><\/li>\n<li><a href=\"#Team\">Working With A Team<\/a><\/li>\n<li><a href=\"#Other\">Other Topics<\/a><\/li>\n<li><a href=\"#Conclusion\">Conclusion<\/a><\/li>\n<\/ol>\n<p><a name=\"Setup\"><\/a><\/p>\n<h4>Setting Up Visual Studio<\/h4>\n<p>Visual Studio crossed the 20-year mark with the release of <em>Visual Studio 2017<\/em>. There are many versions of the product out there, but in general, you should always pick the latest one. This will allow you to use the latest and greatest features, including the most up-to-date compiler. You&#8217;ll also benefit from recent bug fixes and performance improvements.<\/p>\n<p>Visual Studio is available in three different editions: <em>Community<\/em>, <em>Professional<\/em>, and <em>Enterprise<\/em>. The <a href=\"https:\/\/www.visualstudio.com\/vs\/community\/\">Community Edition<\/a> is completely free of charge for small businesses, open source projects, academic research, and classroom learning environments. If you don\u2019t qualify for the Community License, you can purchase the Professional Edition instead. If you work for a large enterprise or simply want the best Visual Studio has to offer, then you should consider the Enterprise Edition. You can <a href=\"https:\/\/www.visualstudio.com\/vs\/compare\/\">compare the offerings<\/a> on the Visual Studio website if you are unsure. This guide is applicable to all editions. <\/p>\n<p><strong><a href=\"https:\/\/www.visualstudio.com\/vs\/\">Download the latest Visual Studio<\/a><\/strong><\/p>\n<p>Once you have downloaded the installer, run it. Visual Studio allows you to choose what <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/the-lightweight-visual-studio-15-installer\/\">workloads <\/a>you want to install, choosing only the components you want, and nothing you don\u2019t. The following workloads are under the C++ umbrella:<\/p>\n<table style=\"border: 2px solid black;width:800px;margin:auto\">\n<tr>\n<td style=\"vertical-align:middle\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/desktop-icon.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/desktop-icon.png\" alt=\"Desktop Workload Icon\" width=\"43\" height=\"46\" \/><\/a><\/td>\n<td style=\"vertical-align:middle\"><strong><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/04\/17\/windows-desktop-development-with-c-in-visual-studio\/\">Desktop development with C++<\/a><\/strong>\nProvides the tools needed for building and debugging classic desktop applications. This includes classic Win32 console applications.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:middle\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/mobile-icon.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/mobile-icon.png\" alt=\"Mobile Workload Icon\" width=\"36\" height=\"40\" class=\"aligncenter size-full wp-image-15275\" \/><\/a><\/td>\n<td style=\"vertical-align:middle\"><strong><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/04\/18\/android-and-ios-development-with-c-in-visual-studio\/\">Mobile development with C++<\/a><\/strong>\nIncludes the tools needed for targeting Android and iOS.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:middle\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/game-icon.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/game-icon.png\" alt=\"Game Workload Icon\" width=\"43\" height=\"41\" class=\"aligncenter size-full wp-image-15276\" \/><\/a><\/td>\n<td style=\"vertical-align:middle\">\n<strong><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/04\/11\/directx-game-development-with-c-in-visual-studio\/\">Game development with C++<\/a><\/strong>\nEnables you to quickly and easily get started building games using DirectX, Unreal Engine, or Cocos2d.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:middle\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/linux-icon.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/linux-icon.png\" alt=\"Linux Workload Icon\" width=\"37\" height=\"43\" class=\"aligncenter size-full wp-image-15286\" \/><\/a><\/td>\n<td style=\"vertical-align:middle\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/linux-development-with-c-in-visual-studio\/\"><strong>Linux development with C++<\/strong><\/a>\nAll the necessary tools for developing and debugging Linux applications.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:middle\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwp-icon.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwp-icon.png\" alt=\"UWP Workload Icon\" width=\"43\" height=\"42\" class=\"aligncenter size-full wp-image-15295\" \/><\/a><\/td>\n<td style=\"vertical-align:middle\"><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/04\/17\/universal-windows-platform-development-with-c\/\"><strong>Universal Windows Platform development<\/strong><\/a>\nThis workload is not specific to just C++, but you can enable the C++ support by checking the individual component for \u201cC++ UWP support\u201d.<\/td>\n<\/tr>\n<\/table>\n<p>There are a variety of other workloads for other languages such as C#, and other platforms such as Microsoft Azure (for your cloud needs). The workloads you install are not permanent, and you can always change these options by opening the installer and selecting <em>Modify<\/em>. <\/p>\n<p><strong>For this guide, please install the Desktop development with C++ workload. <\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/workloads.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/workloads-1024x561.png\" alt=\"Installer Workloads\" width=\"879\" height=\"482\" class=\"aligncenter size-large wp-image-15305\" \/><\/a><\/p>\n<p>Once you have made your selection and clicked <em>Install<\/em>, Visual Studio will begin the installation process. Once it is complete, Visual Studio is all set up and ready to go!<\/p>\n<p>Now let\u2019s look at an actual project. For this next section, if at any time, you cannot find some feature or command that you are looking for, you can search for it via <em><strong>Quick Launch<\/strong><\/em>, the search box at the upper right of the IDE (or press <em>Ctrl+Q<\/em> to get there fast).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/demoApplication.zip\"><strong>Download the demo project<\/strong><\/a><\/p>\n<p><a name=\"Opening\"><\/a><\/p>\n<h4>Opening Projects or Folders of Code<\/h4>\n<p>If you open the demo project folder in Windows File Explorer, you will find a variety of different files in addition to some source code. Generally, code organized by Visual Studio appears as a Solution, which contains a collection of Projects. When a codebase is organized this way, it includes a <em>.sln<\/em> file (which configures the solution) as well as <em>.vcxproj<\/em> files (which configure each project); these files help define things like include paths, compiler settings, and how the projects are connected. <\/p>\n<p>Visual Studio also supports an <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/bring-your-c-codebase-to-visual-studio-with-open-folder\/\">Open Folder mode<\/a> as of Visual Studio 2017 which does away with .sln and .vcxproj files and allows you as the user to configure your own environment independently. This approach is ideal for cross-platform projects that will be run from a variety of different IDEs or editors. Better yet, if you are a CMake user, as of Visual Studio 2017 there is a <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2016\/10\/05\/cmake-support-in-visual-studio\/\">built-in CMake experience<\/a>. This guide will not go over Open Folder or CMake, but you are encouraged to check out the relevant blog posts linked in this paragraph for more information. <\/p>\n<p><strong>To open <em><strong>demoApplication<\/strong><\/em>, double click the <em><strong>.sln<\/strong><\/em> file, or from Visual Studio go to <em>File &gt; Open &gt; Project\/Solution&#8230;<\/em> and navigate to the appropriate solution. <\/strong><\/p>\n<p>Once you have opened the project, a view of the content in the project will appear in the <em><strong>Solution Explorer<\/strong><\/em>, pictured below:<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/solution-explorer1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/solution-explorer1.png\" alt=\"Solution Explorer Window\" width=\"348\" height=\"336\" class=\"aligncenter size-full wp-image-15315\" \/><\/a>\nNew projects can be also created by going to <em>File &gt; New &gt; Project&#8230;<\/em> and selecting the template that is appropriate. Console applications are under <em>Visual C++ &gt; Win32<\/em>.\n<a name=\"Building\"><\/a><\/p>\n<h4>Building the Application<\/h4>\n<p>Visual Studio is closely integrated with the Visual C++ compiler, which makes it easy to build and debug your C++ applications. Near the top of the IDE inside the standard toolbar, there are dropdowns where you can change your build configuration and architecture. You can also easily add more configurations, as needed. For this exercise, you can leave the default settings of <em>Debug <\/em>and <em>x86<\/em>.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug.png\" alt=\"Project Configuration\" width=\"254\" height=\"87\" class=\"aligncenter size-full wp-image-15325\" \/><\/a>\n<strong>Attempt to build the application by going to <em><strong>Build &gt; Build Solution<\/strong><\/em> (or alternatively by pressing <em><strong>F7<\/strong><\/em>). The build will fail, since the code contains an error.<\/strong>\nThe <em><strong>Output Window<\/strong><\/em> is a valuable tool while you are building; it provides information about the status of the build.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/output.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/output-1024x185.png\" alt=\"Output Window\" width=\"879\" height=\"159\" class=\"aligncenter size-large wp-image-15335\" \/><\/a><\/p>\n<h5>Fixing compiler errors<\/h5>\n<p>You should see an error in the <em><strong>Error List<\/strong><\/em> at the bottom of the screen when you attempt to build. With this error, you not only get the location of the problem and a description, but if you double-click the line, you will be brought to the specific location in the code. This makes it easy to quickly navigate to problem areas. <\/p>\n<p><strong>Double-click on the error after building, and fix the offending line of code. <\/strong>\n<a name=\"EditAndNav\"><\/a><\/p>\n<h4>Code Editing &amp; Navigation<\/h4>\n<p>This section provides a glimpse of what is possible in Visual Studio. To learn more about this area please visit the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/c-code-editing-and-navigation-in-visual-studio\/\">C++ Code Editing and Navigation in Visual Studio<\/a> blog post. <\/p>\n<h5>Intellisense<\/h5>\n<p>One of the most useful features for helping you write code quickly in Visual Studio is <em><strong>IntelliSense<\/strong><\/em>, which is a context-aware code completion tool. As you type, Visual Studio will suggest classes, methods, objects, code snippets, and more symbols that make sense in relation to what you have typed so far and where you have typed it. You can scroll up and down the suggestions with the <em>arrow keys<\/em>, and complete symbols with <em>Tab<\/em>.<\/p>\n<p><strong>In the main function try adding a call to the <em><strong>farewell <\/strong><\/em>function to the <em>mySorter <\/em>object. You should see <em>IntelliSense <\/em>pop up with all the possible functions available from the <em>sorter <\/em>class. <\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/intellisense1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/intellisense1.png\" alt=\"IntelliSense\" width=\"566\" height=\"157\" class=\"aligncenter size-full wp-image-15345\" \/><\/a><\/p>\n<h5>Go To<\/h5>\n<p>To efficiently write and understand code, easy code navigation is essential. By using the <em><strong>Go To<\/strong><\/em> feature <em>(Ctrl+T)<\/em> you can quickly get to where you need to go, without taking your hands off the keyboard. When you open the dialog, you can filter your results by clicking on the desired button, or by starting your query with a specific token. For example, you can go to a specific file by opening the <em>Go To <\/em>dialog and typing \u201c<em>f <\/em>\u201d. Another common way to access this dialog is by going to a specific line number; you can do this by opening the menu traditionally and using the \u201c:\u201d token, or by pressing <em>Ctrl+G<\/em>. Try using <em>Go To<\/em> to navigate around the demo project. <\/p>\n<p><strong>Use the <em><strong>Go To<\/strong><\/em> menu <em><strong>(Ctrl+T)<\/strong><\/em> to open the file <em><strong>sorter.h<\/strong><\/em> by typing \u201c<em><strong>f sorter.h<\/strong><\/em>\u201d.\nUse the <em><strong>Ctrl+G<\/strong> <\/em>shortcut to go to <em><strong>line 23<\/strong><\/em> to change the private member \u201c<em><strong>name<\/strong><\/em>\u201d to your name. <\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/go-to.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/go-to.png\" alt=\"Go To\" width=\"455\" height=\"128\" class=\"aligncenter size-full wp-image-15355\" \/><\/a><\/p>\n<h5>Peek\/Go to Definition<\/h5>\n<p>Sometimes it can be challenging to find out where a function or object is defined in your codebase. This problem is easily solved in Visual Studio, where you can easily peek into definitions. Try this in the demo project by selecting the function you want to look at, and pressing <em>Alt+F12<\/em>, or selecting it from the right-click menu. This will bring up a preview of the file where the function is defined, where you can quickly make small edits. Press <em>Esc <\/em>to close the preview window. You can also go directly to the definition by pressing only <em>F12<\/em>. <\/p>\n<p><strong>Use <em><strong>Peek Definition<\/strong><\/em> on the <em><strong>printVector <\/strong><\/em>function by selecting the function and pressing <em><strong>Alt+F12<\/strong><\/em>. <\/p>\n<p>Add a dash between the numbers in the vector when they are printed. <\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/peek-definition1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/peek-definition1.png\" alt=\"Peek Definition Window\" width=\"870\" height=\"334\" class=\"aligncenter size-full wp-image-15365\" \/><\/a><\/p>\n<h5>Rename<\/h5>\n<p>You can also use Visual Studio to refactor existing code. In the demo project, there is a function that has an unhelpful name. Rather than going to each file to change the name of each occurrence manually, choose one of the functions and press <em>Ctrl+R, Ctrl+R<\/em> or right-click it and choose <em>Rename<\/em>. This will bring up a menu where you can choose what you want to rename it to, and then preview the changes before they are committed. <\/p>\n<p><strong>Use Rename <em><strong>(Ctrl+R, Ctrl+R)<\/strong><\/em> to change the method \u201c<em>SILLY_SALUTATION_FUNCTION<\/em>\u201d to something more useful, such as \u201c<em>greeting<\/em>\u201d.<\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/rename.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/rename.png\" alt=\"Rename Refactoring Operation\" width=\"492\" height=\"246\" class=\"aligncenter size-full wp-image-15375\" \/><\/a>\n<a name=\"Debug\"><\/a><\/p>\n<h4>Debugging and Diagnosing Issues<\/h4>\n<p>Once you can successfully build your application and write code easily, the next step is often debugging the application. Debugging can be a complex process, and Visual Studio provides many powerful tools to help along the way. The most commonly used debugging tool is the <em><strong>breakpoint<\/strong><\/em>, so let\u2019s start with that. If you click on the bar to the left of your code, a red circle should appear. If you click the circle, the breakpoint will be removed.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/breakpoint1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/breakpoint1.png\" alt=\"Breakpoint\" width=\"150\" height=\"83\" class=\"aligncenter size-full wp-image-15385\" \/><\/a>\nWhen a breakpoint is set and the program reaches that point of execution, it will stop, allowing you to inspect variables and the current state of the program. <\/p>\n<p><strong>Place a breakpoint on <em><strong>line 33<\/strong><\/em> of <em>demoApplication.cpp<\/em> by clicking the bar to the left of the line numbers. <\/p>\n<p>Click the red circle again to remove the breakpoint.<\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/run.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/run.png\" alt=\"Start Debugging\" width=\"272\" height=\"94\" class=\"aligncenter size-full wp-image-15395\" \/><\/a>\nTo begin debugging, you can either press the green arrow at the top of the IDE or press <em>F5<\/em>. Once the program has stopped on the <em>breakpoint<\/em>, there are many things you can do to help you diagnose problems. One of the best ways to find problems is to understand the current state of the program, versus what it should be. This can be easily achieved by using the <em><strong>Autos Window<\/strong><\/em>, which lists recently used variables and their values. You can also hover your mouse over a variable to see what the current value is. <\/p>\n<p>Do the following: \n<strong><\/p>\n<ol>\n<li>Place a breakpoint on <em><strong>line 14<\/strong> <\/em>of the <em><strong>main <\/strong><\/em>function.<\/li>\n<li>Click the green arrow at the top of the IDE or press <em><strong>F5<\/strong><\/em> to begin debugging.<\/li>\n<li>Find out what the value of <em><strong>testInt <\/strong><\/em>is before it is initialized by hovering over the value in the code.<\/li>\n<li>Look at the value of <em><strong>testInt<\/strong> <\/em>in the <em><strong>Autos window<\/strong><\/em>.<\/li>\n<li>Press the green arrow or <em><strong>F5 <\/strong><\/em>again to stop debugging.<\/li>\n<\/ol>\n<p><\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/break-stop.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/break-stop.png\" alt=\"Breakpoint Stop\" width=\"356\" height=\"147\" class=\"aligncenter size-full wp-image-15406\" \/><\/a>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/autos1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/autos1.png\" alt=\"Autos Window\" width=\"628\" height=\"224\" class=\"aligncenter size-full wp-image-15405\" \/><\/a>\nWhen you have sufficiently understood the current state of the program, you can press the green arrow button or press <em>F5 <\/em>again to have the program run until the next breakpoint. You can also step the program one line at a time if needed by using the arrows at the top.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/stepping.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/stepping.png\" alt=\"Stepping\" width=\"567\" height=\"240\" class=\"aligncenter size-full wp-image-15415\" \/><\/a>\n<em><strong>Step Over<\/strong><\/em> <em>(F10)<\/em> will run through whatever is on the current line, and suspend execution after the function returns. <em><strong>Step Into<\/strong><\/em> <em>(F11)<\/em> will follow the function call of the next line, allowing you to see what is happening inside that function. At any time, you can step out <em>(Shift+F11)<\/em>, which will place the program just after it has completed the current functional scope. Once you are finished debugging you can run the program to its completion, or press the red square (or <em>Shift+F5<\/em>) at the top of the IDE to stop the debugging session. <\/p>\n<p><strong>Use a combination of these to explore the demo project and see if you can fix the logical bug in the sort algorithm (Hint: it is in the sort algorithm itself). <\/strong><\/p>\n<p>There are many more tools within Visual Studio that can help you profile and debug your applications. Check out the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/c-debugging-and-diagnostics\/\">C++ Debugging and Diagnostics<\/a> blog post to learn more. \n<a name=\"Testing\"><\/a><\/p>\n<h4>Testing<\/h4>\n<p>Visual Studio has a built-in test framework to help you unit test your projects, ensuring that the code you write is working as expected. To test the demo project, which is a native console application, you can add a <em>Native Unit Test Project<\/em> to the solution. <\/p>\n<p><strong>Add a test project to the demo. This is done by going to <em><strong>File &gt; New &gt; Project<\/strong><\/em> then selecting <em><strong>Visual C++ &gt; Test &gt; Native Unit Test Project<\/strong><\/em>. Make sure to choose the <em><strong>Add to solution<\/strong><\/em> option in the Solution dropdown. You can also simply right-click your solution name in the <em><strong>Solution Explorer<\/strong><\/em> and choose <em><strong>Add &gt; New Project<\/strong><\/em> to accomplish the same task. <\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/create-test-project.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/create-test-project.png\" alt=\"Create Test Project\" width=\"942\" height=\"653\" class=\"aligncenter size-full wp-image-15425\" \/><\/a>\nOnce you have added a unit test, you can open the <em>.cpp<\/em> file and see the basic testing skeleton in the template, and begin to add tests. <\/p>\n<p><strong>Add a test method, making sure that it will pass. Try the following code:<\/strong>\n<code>TEST_METHOD(TestMethod1)  \n{  \nAssert::AreEqual(1,1);  \n}  <\/code>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/assert.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/assert.png\" alt=\"Writing An Assert\" width=\"577\" height=\"362\" class=\"aligncenter size-full wp-image-15435\" \/><\/a>\nOnce you have added a test, you can run the test by going to <em>Test &gt; Run &gt; All Tests<\/em> in the menu at the top of the IDE. Once you have run the tests, you will see the results in the <em><strong>Test Explorer<\/strong><\/em> window.<\/p>\n<p><strong>Run your test by going to <em><strong>Test &gt; Run &gt; All Tests<\/strong><\/em>. Try adding another test that will fail, and running the tests again. <\/strong>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/test-explorer1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/test-explorer1.png\" alt=\"Test Explorer Window\" width=\"352\" height=\"186\" class=\"aligncenter size-full wp-image-15437\" \/><\/a>\nIf you would like to find out more information about unit testing, including how to connect your test project to your code under test, and check the code coverage of your unit tests, check out the <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/04\/19\/cpp-testing-in-visual-studio\/\">C++ Unit Testing in Visual Studio<\/a> blog post. \n<a name=\"Team\"><\/a><\/p>\n<h4>Working with A Team<\/h4>\n<p>It is very common these days to be working on a project with a team, and Visual Studio makes collaboration with others easy! You can easily create new source control repositories using <em>Git <\/em>or <em>Team Foundation Server<\/em> to manage your codebase. To create a new repo for a project, click the <em>Add to Source Control<\/em> button at the bottom of the screen, and add the opened project to the source control system of your choice. \n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/add-to-source-control.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/add-to-source-control.png\" alt=\"Add to Source Control\" width=\"400\" height=\"164\" class=\"aligncenter size-full wp-image-15445\" \/><\/a>\nOnce you do that, a local repository will be made for your project. From here you can make commits, or push your changes to a remote <em>Git<\/em> service such as GitHub. This is all managed in the <em><strong>Team Explorer<\/strong><\/em> window.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/team-explorer.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/team-explorer.png\" alt=\"Team Explorer Window\" width=\"377\" height=\"419\" class=\"aligncenter size-full wp-image-15455\" \/><\/a><\/p>\n<p><strong>Try adding the demo project to source control, and pushing it to GitHub. This is done by pressing the <em><strong>Add to source control<\/strong><\/em> button, and then pushing to a remote repository inside the <em><strong>Team Explorer<\/strong><\/em>. <\/strong><\/p>\n<p>You can also very easily clone from source control from the <em>Team Explorer<\/em> window. Choose <em>Projects &gt; New Repository<\/em>, and then follow the prompts to clone the project. From here, all you must do is paste in the URL, and the project will be cloned.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/clone1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/clone1.png\" alt=\"Clone Project\" width=\"373\" height=\"249\" class=\"aligncenter size-full wp-image-15465\" \/><\/a>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/clone2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/clone2.png\" alt=\"Clone Project\" width=\"355\" height=\"255\" class=\"aligncenter size-full wp-image-15475\" \/><\/a>\nTo learn more about working on a project as a team in Visual Studio, check out the <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/04\/10\/visual-studio-for-teams-of-cpp-developers\/\">Visual Studio for Teams of C++ Developers<\/a> blog post. \n<a name=\"Other\"><\/a><\/p>\n<h4>Other Topics<\/h4>\n<p>There are many other useful things Visual Studio can do. So many things, in fact, it is hard to cover it all in one guide. Follow the links below to find out more on how to get the most out of Visual Studio.<\/p>\n<h5>Code Analysis<\/h5>\n<p>Visual Studio by default catches a lot of code issues, but its <em><strong>Code Analysis<\/strong><\/em> tool can often uncover hard-to-find issues that would normally be missed. Common errors that are reported include buffer overflows, uninitialized memory, null pointer dereferences, and memory and resource leaks. This functionality is built into the IDE, and can easily be used to help you write better code. Try it out by going to the <em>Analyze <\/em>menu and choosing <em>Run Code Analysis &gt; On Solution<\/em>. Learn more about <em>Code Analysis<\/em> as well as the C++ Core Guidelines Checkers in the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/cppcorecheck\/\">announcement blog post<\/a>. <\/p>\n<h5>Library Acquisition<\/h5>\n<p>Library acquisition in C++ can be challenging. While Visual Studio has support for <em>NuGet <\/em>package management, more recently a new tool called <em><strong>vcpkg <\/strong><\/em>was launched. <em>Vcpkg <\/em>is an open source tool maintained by Microsoft that simplifies acquiring and building open source libraries, with over 200 currently supported. This tool, while separate from Visual Studio itself, is a valuable companion for any C++ developer on Windows. Check out the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/vcpkg-a-tool-to-acquire-and-build-c-open-source-libraries-on-windows\/\">announcement blog post<\/a> for details. \n<a name=\"Conclusion\"><\/a><\/p>\n<h4>Conclusion<\/h4>\n<p>We hope that this guide has allowed you to get up to speed with Visual Studio quickly, and that you have learned some of the core functionality. This should be enough to get you started, but there are still many more features that could not be covered in this guide. The Visual C++ Blog is a very useful resource to find out more about not only the product overall, but also what we are currently working on and changing. You can find the comprehensive product documentation on <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/create-portable-custom-editor-options\">docs.microsoft.com<\/a> as well. Now get out there and build something amazing!<\/p>\n<p>We are constantly trying to improve, so if you have any feedback or suggestions for us, please feel free to reach out to us anytime! We can be reached via email at <em>visualcpp at microsoft.com<\/em> and you can provide feedback via <em>Help &gt; Report A Problem<\/em> in the product, or via <a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\">Developer Community<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you new to Visual Studio and working with C++? Then you\u2019ve come to the right place. Whether you\u2019re a student writing one of your first programs or a seasoned C++ developer with years of experience, you&#8217;ll find Visual Studio to be a powerful environment for C++ development. Visual Studio is an IDE packed with [&hellip;]<\/p>\n","protected":false},"author":326,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-15255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>Are you new to Visual Studio and working with C++? Then you\u2019ve come to the right place. Whether you\u2019re a student writing one of your first programs or a seasoned C++ developer with years of experience, you&#8217;ll find Visual Studio to be a powerful environment for C++ development. Visual Studio is an IDE packed with [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/15255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/326"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=15255"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/15255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=15255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=15255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=15255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}