Documentation
Topics Overview Overview Linux macOS Windows VS Code for the Web Raspberry Pi Network Additional Components Uninstall VS Code Tutorial Copilot Quickstart User Interface Personalize VS Code Install Extensions Tips and Tricks Intro Videos Overview Setup Quickstart Overview Language Models Context Tools Agents Customization Trust & Safety Overview Agents Tutorial Agents Window Planning Memory Tools Subagents Local Agents Copilot CLI Cloud Agents Third-Party Agents Overview Chat Sessions Add Context Inline Chat Review Edits Checkpoints Artifacts Panel Debug Chat Interactions Prompt Examples Overview Instructions Prompt Files Custom Agents Agent Skills Language Models MCP Hooks Plugins Context Engineering Customize AI Test-Driven Development Edit Notebooks with AI Test with AI Test Web Apps with Browser Tools Debug with AI MCP Dev Guide OpenTelemetry Monitoring Inline Suggestions Smart Actions Best Practices Security Troubleshooting FAQ Cheat Sheet Settings Reference MCP Configuration Workspace Context Display Language Layout Keyboard Shortcuts Settings Settings Sync Extension Marketplace Extension Runtime Security Themes Profiles Overview Voice Interactions Command Line Interface Telemetry Basic Editing IntelliSense Code Navigation Refactoring Snippets Overview Multi-Root Workspaces Workspace Trust Tasks Debugging Debug Configuration Testing Port Forwarding Integrated Browser Overview Quickstart Staging & Committing Branches & Worktrees Repositories & Remotes Merge Conflicts Collaborate on GitHub Troubleshooting FAQ Getting Started Tutorial Terminal Basics Terminal Profiles Shell Integration Appearance Advanced Overview Enterprise Policies AI Settings Extensions Telemetry Updates Overview JavaScript JSON HTML Emmet CSS, SCSS and Less TypeScript Markdown PowerShell C++ Java PHP Python Julia R Ruby Rust Go T-SQL C# .NET Swift Working with JavaScript Node.js Tutorial Node.js Debugging Deploy Node.js Apps Browser Debugging Angular Tutorial React Tutorial Vue Tutorial Debugging Recipes Performance Profiling Extensions Tutorial Transpiling Editing Refactoring Debugging Quick Start Tutorial Run Python Code Editing Linting Formatting Debugging Environments Testing Python Interactive Django Tutorial FastAPI Tutorial Flask Tutorial Create Containers Deploy Python Apps Python in the Web Settings Reference Getting Started Navigate and Edit Refactoring Formatting and Linting Project Management Build Tools Run and Debug Testing Spring Boot Modernizing Java Apps Application Servers Deploy Java Apps GUI Applications Extensions FAQ Intro Videos GCC on Linux GCC on Windows GCC on Windows Subsystem for Linux Clang on macOS Microsoft C++ on Windows Build with CMake CMake Tools on Linux CMake Quick Start C++ Dev Tools for Copilot Editing and Navigating Debugging Configure Debugging Refactoring Settings Reference Configure IntelliSense Configure IntelliSense for Cross-Compiling FAQ Intro Videos Get Started Navigate and Edit IntelliCode Refactoring Formatting and Linting Project Management Build Tools Package Management Run and Debug Testing FAQ Overview Node.js Python ASP.NET Core Debug Docker Compose Registries Deploy to Azure Choose a Dev Environment Customize Develop with Kubernetes Tips and Tricks Overview Jupyter Notebooks Data Science Tutorial Python Interactive Data Wrangler Quick Start Data Wrangler PyTorch Support Azure Machine Learning Manage Jupyter Kernels Jupyter Notebooks on the Web Data Science in Microsoft Fabric Foundry Toolkit Overview Foundry Toolkit Copilot Tools Create Agents Models Playground Agent Builder Agent Inspector Evaluation Tool Catalog Fine-Tuning (Automated Setup) Fine-Tuning (Project Template) Model Conversion Tracing Profiling (Windows ML) FAQ File Structure Manual Model Conversion Manual Model Conversion on GPU Setup Environment Without Foundry Toolkit Template Project Migrating from Visualizer to Agent Inspector Overview Getting Started Resources View Deployment VS Code for the Web - Azure Containers Azure Kubernetes Service Kubernetes MongoDB Remote Debugging for Node.js Overview SSH Dev Containers Windows Subsystem for Linux GitHub Codespaces VS Code Server Tunnels SSH Tutorial WSL Tutorial Tips and Tricks FAQ Overview Tutorial Attach to Container Create Dev Container Advanced Containers devcontainer.json Dev Container CLI Tips and Tricks FAQ Default Keyboard Shortcuts Default Settings Substitution Variables Tasks SchemaOn this page there are 3 sections
Editing and Navigating C++ Code
This article provides an overview of code editing and navigating features specific to the C/C++ extension. For more information about general editing and navigating in Visual Studio Code, see Basic Editing and Code Navigation.
Editing C++ code
The source code editing features provided by the C/C++ extension are powerful tools for editing, formatting, and understanding your codebase.
Identifying header files
To provide the best editing experience, the C++ extension needs to know where to find each header file that is referenced in your code. By default, the extension searches the current source directory, its subdirectories, and some platform-specific locations. If a referenced header file can't be found, a red squiggle is displayed underneath the #include directive.
To specify additional include directories,
- Select an #include path that has no reference.
- Select the light bulb that appears and choose Edit "includePath" setting, which opens the C/C++ extension's Settings editor.
- Under the Include Path section, you can specify the paths for any additional include directories.
List members
When you type a member access symbol (. or ->), the editor displays a list of members. As you type more letters, the list is filtered in real time:
Code formatting
The C/C++ extension for Visual Studio Code supports source code formatting using clang-format and vc_format. Both of these formatting options are included in the extension, with clang-format being the default.
You can format an entire file with Format Document (⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I)) or just the current selection with Format Selection (⌘K ⌘F (Windows, Linux Ctrl+K Ctrl+F)) in right-click context menu. You can also trigger formatting based on user gestures such as typing, saving, and pasting with the following settings:
- editor.formatOnSave - to format when you save your file.
- editor.formatOnType - to format as you type (triggered on the ; character).
To learn more about formatting, see Formatting.
Clang-format
By default, the clang-format style is set to file. This means that if a .clang-format file is found in your workspace, the settings specified in the file are used as the formatting reference. Otherwise formatting is based on the default style specified in the C_Cpp.clang_format_fallbackStyle setting.
Currently, the default formatting style is Visual Studio, an approximation of the default code formatter in Visual Studio. It implies the following settings:
"C_Cpp.clang_format_path": "C:\\Program Files (x86)\\LLVM\\bin\\clang-format.exe"vc_format
By default, if an .editorconfig file with relevant settings is identified near the code being formatted, the Visual C++ formatting engine is used instead of clang-format. Otherwise, navigate to the C_Cpp.formatting setting and set it to vc_format to use the Visual C++ formatting engine.
Enhanced semantic colorization
When IntelliSense is enabled, the Visual Studio Code C/C++ extension supports semantic colorization. For more information about setting colors for classes, functions, variables, and more, see Enhanced colorization. For more information on configuring IntelliSense, see IntelliSense configuration.
Quick Info
You can hover over a symbol to see an inline view of its definition:
Doxygen comments
Doxygen is a tool that generates documentation from source code. When you annotate code with comments, Doxygen then generates documentation for these functions. For doxygen comments, type /** and press Enter to generate a doxygen comment block. Supported doxygen tags include: @brief,@tparam, @param, @return, @exception, @deprecated, @note, @attention, and @pre.
Markdown comments
By default, the C++ extension supports showing a subset of markdown in your editor. This subset supports all markdown comments except the symbols _ and *. Toggle the new Markdown in Comments setting to either enable all markdown, keep this subset of markdown, or disable markdown support.
Navigate source code
The source code navigation features can help improve your understanding of your codebase. These let you quickly search for symbols in your code, navigate to their definitions, or find references to them.
Navigation is powered by a set of tags stored in a local database of symbol information. Whenever a folder containing C++ source code files is opened, the C/C++ extension creates a database of the symbols defined in those files. This database is updated whenever a file is changed. If a document is closed without saving, the database is updated to the last saved state.
Search for symbols
You can search for symbols in the current file or workspace to navigate your code more quickly.
To search for a symbol in the current file, press ⇧⌘O (Windows, Linux Ctrl+Shift+O), then enter the name of the symbol you're looking for. A list of potential matches appears, which is filtered as you type. Choose from the list of matches to navigate to that symbol's location.
To search for a symbol in the current workspace, press ⌘T (Windows, Linux Ctrl+T), then enter the name of the symbol. A list of potential matches will appear. If the match you choose is located in a file that's not already open, the file will be opened before navigating to the match's location.
You can also search for symbols by accessing these commands through the Command Palette(⇧⌘P (Windows, Linux Ctrl+Shift+P)). Use Quick Open (⌘P (Windows, Linux Ctrl+P)), then enter the @ command to search the current file, or the # command to search the current workspace. ⇧⌘O (Windows, Linux Ctrl+Shift+O) and ⌘T (Windows, Linux Ctrl+T) are shortcuts for the @ and # commands.
Call hierarchy
The Call Hierarchy view shows all calls to or from a function. It lets you understand the complex calling relationships between the functions in your source code.
To view the call hierarchy, select a function, right-click to display the context menu, and choose Show Call Hierarchy. You can also use the keyboard shortcut (Shift+Alt+H on Windows), or invoke the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and run the command Calls: Show Call Hierarchy. This populates the call tree in the side bar with all of the functions called by your selected function.
Toggle the phone icon in the side bar menu to switch to incoming calls. Incoming calls show whenever your function is referenced by another function. You can also explore nested calls by selecting a function already shown in the call tree and right-clicking on that function to view the available commands.
Peek
The Peek feature displays a few lines of code inside a peek window, so that you don't have to navigate away from your current location. It's useful for quickly understanding the context of a symbol without having to navigate away from your current code.
To open a peek window, navigate to the context menu by right-clicking, then select Peek. There, you can choose to peek at a symbol's definition, declaration, type definition, or references.
With the peek window open, you browse the list of results shown to find the one you're interested in. If you want to navigate to the location of one of these results, select the result or double-click in the source code displayed on the left-hand side of the peek window.
Go to definition
Use the Go to Definition feature to quickly navigate to where a symbol is defined in your source code. Select a symbol in your source code and then press F12, or right-click and choose Go to Definition from the context menu. When there's only one definition of the symbol, you are navigated directly to its location, otherwise the competing definitions are displayed in a peek window as described in the previous section.
If no definitions can be found for the symbol you selected, the C/C++ extension automatically searches for a declaration of the symbol.
Go to declaration
Use the Go to Declaration feature to navigate to the location where a symbol is declared in your source code. This feature functions the same as Go to Definition, but for declarations. Select a symbol in your source code, right-click, and choose Go to Declaration from the context menu. This navigates you to the location of the symbol's declaration.
Go to references
Use the Go to References feature to understand how often and where a symbol is referenced in your source code. Select a symbol in your source code and press ⇧F12 (Windows, Linux Shift+F12) or right-click and choose Go to References from the context menu. If any references are found, they are displayed in a peek window.
Go to type definition
Use the Go to Type Definition feature to jump to where a type is defined in your source code. Select a type in your source code, right-click to open the context menu, and choose Go to Type Definition.
Next steps
Read on to find out about:
- Debugging C++ Code
- Configure IntelliSense
- Configure VS Code for MSVC
- Configure VS Code for Mingw-w64 and GCC
- Configure VS Code for macOS
- Basic Editing in VS Code
- Code Navigation in VS Code
- Tasks in VS Code
If you have any other questions or run into any issues, please file an issue on GitHub. You might be asked to provide logging information from the extension to help diagnose the issue. See C/C++ extension logging for help on providing extension logs.