Skip to content

Visual Studio Code

While you’re free to use any code editor you’re comfortable with, I highly recommend using Visual Studio Code. It’s lightweight, beginner-friendly, and comes with powerful extensions that can streamline your workflow for CSCE240.

I HIGHLY recommend you get the C/C++ extension by Microsoft. It’s going to add language support for C++ such as Intellisense which is going to help tremendously when developing your programs.

Click on your Extensions tab and enter c++ in the search bar. The extension should be the first to appear in the search results with over 70 million downloads.

the recommended VSCode extensions for C++

Remember in the Style Requirements page when I mentioned that some code editors can be configured to automatically format your code? Well VSCode just so happens to be one of those 😊 editors! You can setup auto-formatting the quick method by copying some code, or if you want to practice customizing your editor you can follow the slower method:

  1. Create a folder called .vscode in your root folder

  2. Create a file called settings.json and copy the following code:

    settings.json
    {
    "[cpp]": {
    "editor.formatOnSave": true, // formats on save
    "editor.defaultFormatter": "ms-vscode.cpptools" // added by C++ extension
    },
    "C_Cpp.clang_format_fallbackStyle": "Google", // if no clang format file use Google
    "C_Cpp.formatting": "clangFormat" // looks for clang format file
    }
  1. In VSCode, Click on File -> Hover Over Preferences, and Click Settings

    how to find the preferences option in VSCode

  2. Search for @lang:cpp format -> Click on the Workspace tab -> Check Editor: Format On Save.

    how to add "format on save" option in vscode

  3. Search for c_cpp -> Click on Formatting under C/C++ -> Edit the C_Cpp: Clang_format_fallback Style to be Google

    how to change the fallback formatting style for c++ to Google in vscode

  4. Finally scroll down to C_Cpp: Formatting and select clangFormat. Above that section is C_Cpp: Clang_format_style and its value should be file.

    how to change the default formatter for c++ to clang in vscode

  5. You should now have a folder called .vscode in your root folder along with a file inside it called settings.json

    Check that the code in settings.json is similar to the following:

    settings.json
    {
    "[cpp]": {
    "editor.formatOnSave": true, // formats on save
    "editor.defaultFormatter": "ms-vscode.cpptools" // added by C++ extension
    },
    "C_Cpp.clang_format_fallbackStyle": "Google", // if no clang format file use Google
    "C_Cpp.formatting": "clangFormat" // looks for clang format file
    }

Create a file called test.cc in the root folder. The following should be your current file structure:

  • DirectoryCSCE240
    • Directory.vscode
      • settings.json
    • test.cc

Copy the code in the Before tab and use ctrl/cmd + s to save. Your code should of been formatted to look like the After tab’s code! Auto-formatting has now been 🚀 implemented! Though not perfect, it will handle most of those pesky style requirements.

test.cc
// Before Saving
#include <iostream>
using std::cout;
using std::endl;
int main() {
cout << "a very very long sentence that needs to be formatted in order to pass the Google Style Requirements" << endl;
return 0;
}