{"id":204,"date":"2026-04-16T04:00:10","date_gmt":"2026-04-16T04:00:10","guid":{"rendered":"https:\/\/sites.tntech.edu\/acrockett\/?p=204"},"modified":"2026-04-16T04:00:11","modified_gmt":"2026-04-16T04:00:11","slug":"vs-code-write-compile-run-a-c-program","status":"publish","type":"post","link":"https:\/\/sites.tntech.edu\/acrockett\/2026\/04\/16\/vs-code-write-compile-run-a-c-program\/","title":{"rendered":"VS Code: Write, Compile, &amp; Run a C++ Program"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Creating a Workspace in VS Code (helloworld example)<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>If you do not already have VS Code open, then <strong>open it<\/strong>.<br><\/li>\n\n\n\n<li>On the left side menu, click on the <strong>Explorer <\/strong>Icon. The Explorer allows you to open folders and create files.<br><img loading=\"lazy\" decoding=\"async\" width=\"293\" height=\"342\" class=\"wp-image-197\" style=\"width: 150px\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/explorer.png\" alt=\"explorer\" srcset=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/explorer.png 293w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/explorer-257x300.png 257w\" sizes=\"auto, (max-width: 293px) 100vw, 293px\" \/><br><\/li>\n\n\n\n<li>Click the blue <strong>Open Folder<\/strong> button.<br><\/li>\n\n\n\n<li>Navigate in the <strong>Open Folder<\/strong> window to where you want to save your programs for this course. I am going to <strong>navigate<\/strong> to C:\/CSC 1300\/ and then click the <strong>Select Folder<\/strong> button.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/open-folder.png\" alt=\"open folder\"><br><br><\/li>\n\n\n\n<li>You may see a &#8220;<strong>Do you trust the authors of the files in this folder?<\/strong>&#8221; message. If you do, <strong>click the checkbox<\/strong> beside &#8220;Trust the authors of all the files in the parent&#8221; and click on the blue button &#8220;<strong>Yes, I trust the authors<\/strong>&#8220;.<br><\/li>\n\n\n\n<li>Now that this folder is open in the Explorer window, you can how hover beside the folder name and 4 icons will appear.\n<ul class=\"wp-block-list\">\n<li><span style=\"color: initial\">The first icon is <\/span><strong style=\"color: initial\">New File<\/strong><\/li>\n\n\n\n<li><span style=\"color: initial\">The second icon is <\/span><strong style=\"color: initial\">New Folder<\/strong><\/li>\n\n\n\n<li><span style=\"color: initial\">The third icon is <\/span><strong style=\"color: initial\">Refresh Explorer<\/strong><\/li>\n\n\n\n<li>The fourth icon is <strong>Collapse Folders in Explorer<\/strong><br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/4-icons.png\" alt=\"4 icons\"><br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Click on the <strong>New Folder<\/strong> icon to create a new folder in the folder that you opened and name it <strong>helloworld<\/strong>.<br><\/li>\n\n\n\n<li>Then, <strong>click on the helloworld folder<\/strong>, which will cause the arrow beside it to point downward instead of to the right.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/helloworld-folder.png\" alt=\"helloworld folder\"><\/li>\n<\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">Create a Source File (C++ Program) <\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Then, click on the <strong>New File<\/strong> icon to create a file inside of the <strong>helloworld <\/strong>folder and name the file <strong><code><mark>helloworld.cpp<\/mark><\/code><\/strong>.<br><br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/click-new-file.png\" alt=\"new file\"><br><\/li>\n\n\n\n<li><strong>Type<\/strong> the following lines of code in your newly created <strong>helloworld.cpp <\/strong>file.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/helloworld-code.png\" alt=\"helloworld code\"><br><\/li>\n\n\n\n<li>Now press&nbsp;<strong>Ctrl + S<\/strong>&nbsp;to save the file. <br>You can also alternately click on <strong>File<\/strong> and then <strong>Save<\/strong>.<\/li>\n<\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">Set Up Auto Save<\/h1>\n\n\n\n<p>You can enable <strong>Auto Save<\/strong>&nbsp;to automatically save your file changes, by clicking on <strong>File<\/strong> at the top and then scrolling down to click on&nbsp;<strong>Auto Save<\/strong>.<\/p>\n\n\n\n<p>The Activity Bar on the edge of Visual Studio Code lets you open different views such as&nbsp;<strong>Search<\/strong>,&nbsp;<strong>Source Control<\/strong>, and&nbsp;<strong>Run<\/strong>. You can find out more about the other views in the VS Code at the link <a href=\"https:\/\/code.visualstudio.com\/docs\/getstarted\/userinterface\"><strong>https:\/\/code.visualstudio.com\/docs\/getstarted\/userinterface<\/strong><\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Creating a Build Task to be able to Compile &amp; Run helloworld.cpp Within VS Code<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>While you are still in VS Code with your helloworld.cpp source file open, click <strong><code><mark>CTRL + Shift + P<\/mark><\/code> <\/strong><br>(<strong><code><mark>CMD + Shift + P<\/mark><\/code><\/strong> on a Mac) on your keyboard, which is used to <strong>Create the Build Task<\/strong>.<br><\/li>\n\n\n\n<li>A menu will appear at the top. Type &#8220;<strong>Tasks: Configure Task<\/strong>&#8221; and select this option that appears.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/configure-build-task.png\" alt=\"configure task\"><br><\/li>\n\n\n\n<li>Under the <strong>Select a task to configure <\/strong>menu, choose <strong>C\/C++: g++.exe build active file<\/strong> from the list of options.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/select-task-to-configure.png\" alt=\"Select g++ exe build task\"><br><\/li>\n\n\n\n<li>VS Code will generate a folder named <strong><code><mark>.vscode<\/mark><\/code><\/strong> within your <strong>helloworld <\/strong>directory and a <strong><code><mark>tasks.json<\/mark><\/code><\/strong> file within the <code><mark><strong>.vscode<\/strong><\/mark><\/code> folder. It will also automatically open the <strong><code><mark>tasks.json<\/mark><\/code><\/strong> so you can edit it.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/tasks.json_.png\" alt=\"tasks.json\"><br><\/li>\n\n\n\n<li>Modify the compile args (arguments) as shown below:<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/compile-flags.png\" alt=\"compile flags\"><br><\/li>\n\n\n\n<li>If your project has more than one source file, then you will need to modify this as shown below.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/list-out-all-the-source-files.png\" alt=\"list out all the sources\"> <br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/compile-with-wildcard.png\" alt=\"compile with wildcard\"><br><\/li>\n\n\n\n<li>Open a <strong>Terminal <\/strong>so you can compile and run. <strong>Click on Terminal<\/strong> and then <strong>Run Terminal<\/strong>. If you do not see the Terminal link at the top, click on the<strong> three dots <\/strong>and then you will see Terminal.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/open-terminal.png\" alt=\"open terminal\"><br><\/li>\n\n\n\n<li>This will open the terminal.<br><\/li>\n\n\n\n<li>Then, build the file by clicking CTRL+Shift+B (or CMD+Shift+B on a Mac) and select C\/C++:g++.exe build active file, which will open a Terminal and compile the file using your tasks.json file.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/select-MinGW-compiler.png\" alt=\"select build\"><br><\/li>\n\n\n\n<li>If it is able to be compiled, you will see &#8220;Build finished successfully.&#8221;<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/build-finished-successfully.png\" alt=\"build finished successfully\"><br><\/li>\n\n\n\n<li>If there are errors (or warnings), you will see the errors listed and then &#8220;<strong>Build finished with errors.<\/strong>&#8220;<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/errors.png\" alt=\"errors\"><br><\/li>\n\n\n\n<li>Open a <strong>Terminal <\/strong>so you can run the program. <strong>Click on Terminal<\/strong> and then <strong>Run Terminal<\/strong>. If you do not see the Terminal link at the top, click on the <strong>three dots <\/strong>and then you will see Terminal.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/open-terminal.png\" alt=\"open terminal\"><br><\/li>\n\n\n\n<li>Then, you will have to navigate to the location of your <strong>helloworld <\/strong>folder by typing <br><code><mark><strong>cd helloworld<\/strong><\/mark><\/code>. Then, you can run the program by typing <code><mark><strong>.\/helloworld<\/strong><\/mark><\/code>, which will run the <strong>helloworld.exe<\/strong> file.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/run-executable.png\" alt=\"run executable\"><\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Explore IntelliSense<\/h1>\n\n\n\n<p>IntelliSense is an intelligent code-completion tool that includes several features such as list members, parameter information, quick information, and complete word.&nbsp; These features help you to learn more about the code you\u2019re using, keep track of the parameters you\u2019re typing, and add calls to properties and methods with just a few keystrokes.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Red Squiggles<\/h2>\n\n\n\n<p>Go to the <strong>helloworld.cpp<\/strong> file used in an earlier example. Create a Dog struct in this file like the one below and purposefully leave off the semi-colon when creating the Dog age data member.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/red-squiggly.png\" alt=\"red squiggly\"><\/p>\n\n\n\n<p><strong>Do you see the red squiggly line?<\/strong> Hover over the line to see a mini-version of the compile error. Note that compiling the source file is still the best way to thoroughly test your code. Also, please know that sometimes the red squiggly lines can sometimes be buggy &#8211; they can appear when they shouldn&#8217;t and vice versa. So<strong> trust the red squiggles WITH CAUTION<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Auto-Adding Code<\/h2>\n\n\n\n<p>Another thing that IntelliSense does is auto-fill in some code like the data members of a structure after typing the dot operator. See example below.<br><img decoding=\"async\" src=\"http:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2026\/04\/Dog-member-appear.png\" alt=\"dog member\"><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating a Workspace in VS Code (helloworld example) Create a Source File (C++ Program) Set Up Auto Save You can enable Auto Save&nbsp;to automatically save your file changes, by clicking on File at the top and then scrolling down to click on&nbsp;Auto Save. The Activity Bar on the edge of Visual Studio Code lets you [&hellip;]<\/p>\n","protected":false},"author":119,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[24,25,18,23],"class_list":{"0":"post-204","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-c","7":"tag-24","8":"tag-25","9":"tag-c","10":"tag-setting-up-computer","11":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":1,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":220,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/204\/revisions\/220"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}