亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
Install Required Tools
Set Up launch.json and tasks.json
Run and Debug Your Program
Tips for Smooth Debugging
Home Development Tools VSCode How to run and debug a C program in VSCode?

How to run and debug a C program in VSCode?

Oct 16, 2025 am 11:35 AM
vscode c++

To run and debug C in VSCode, first install a C compiler like g or MinGW-w64, the Microsoft C/C extension, and build tools. Then, create a C file and press F5 to generate launch.json for debugging and tasks.json for building. Use Ctrl Shift B to build the code, run the output executable in the terminal, and press F5 to debug with breakpoints. Ensure main() exists, use the -g flag in tasks.json for debug info, and verify executable paths and toolchain setup for smooth operation.

How to run and debug a C   program in VSCode?

To run and debug a C program in VSCode, you need to set up your environment with the right tools and configuration files. Here's how to do it step by step.

Install Required Tools

Before running or debugging C code, make sure you have the following installed:

  • C Compiler: Install g (on Linux/macOS) or MinGW-w64 (on Windows). You can verify installation by running g --version in the terminal.
  • VSCode Extensions: Install the C/C extension by Microsoft from the Extensions marketplace.
  • Build Tools: On Windows, consider installing MSYS2 or Visual Studio Build Tools if using MSVC.

Set Up launch.json and tasks.json

VSCode uses JSON files to define build and debug behavior. These files go in a .vscode folder in your project root.

To generate them:

  • Create a C file (e.g., main.cpp).
  • Press F5 to debug. VSCode will prompt you to create a launch.json file.
  • Select C (GDB/LLDB) or C (Windows) depending on your system.
  • Choose g .exe Build and Debug Active File if using MinGW on Windows, or equivalent.

This automatically creates both launch.json (for debugging) and tasks.json (for building).

Run and Debug Your Program

Once configured:

  • Build: Press Ctrl Shift B to compile using the task defined in tasks.json.
  • Run: After building, open the integrated terminal (Ctrl `) and run the output executable: ./a.out (Linux/macOS) or a.exe (Windows).
  • Debug: Press F5 to start debugging. Set breakpoints by clicking left of the line numbers.

The debugger lets you inspect variables, step through code, and view the call stack.

Tips for Smooth Debugging

  • Make sure your main.cpp has a valid int main() function.
  • If debugging fails, check the full path to your executable in launch.json.
  • Use -g flag in tasks.json to include debug info during compilation.
  • On Windows with MinGW, ensure gdb is in your PATH.

Basically, once the toolchain is set up and config files are generated, running and debugging becomes straightforward with F5 and Ctrl Shift B.

The above is the detailed content of How to run and debug a C program in VSCode?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

How to work with std::any in C How to work with std::any in C Sep 23, 2025 am 06:45 AM

std::any is a type-safe arbitrary type storage tool introduced by C 17. It can be used to save and retrieve any replicable types. It is suitable for scenarios such as configuring systems, plug-in interfaces, etc. that require heterogeneous data containers; it must include header files when using it, and the values ??are safely extracted through std::any_cast, and checked for types with .type() and typeid to avoid exceptions; it supports custom type storage, but does not support direct storage of move-only types, and can be solved through std::unique_ptr packaging; there is performance overhead and no implicit type conversion, which is suitable for dynamic type requirements of non-performance critical paths, but should not replace templates or polymorphic mechanisms. When using it, it must be ensured that the type matches before extraction is performed to ensure that

C   std::format example C std::format example Sep 24, 2025 am 01:29 AM

std::format is a modern formatting tool introduced by C 20. 1. Supports basic string formatting, such as std::format("Hello,{}!","World"); 2. Parameters can be referenced by position, such as {0}, {1}; 3. Provides digital conversion ({:#x}, {:#b}), fill ({:06}) and alignment ({:>8}); 4. Controls floating point accuracy ({:.2f}) and scientific notation ({:.2e}); 5. The formatting time needs to be passed into std::tm, such as {:%Y-%m-%d}; 6. Supports custom types, and specializes std::forma

How to convert a string to uppercase in C How to convert a string to uppercase in C Sep 25, 2025 am 02:18 AM

Use std::transform combined with ::toupper to convert the string to uppercase, such as std::transform(str.begin(), str.end(), str.begin(),::toupper). This method is suitable for ASCII characters. Modify the original string. If you need to keep the original string, you can copy it first. It is recommended to use the ICU library in Unicode scenarios.

How to link a library with your C   code How to link a library with your C code Sep 23, 2025 am 05:08 AM

TolinkalibraryinC ,includeheaderswith#includeanduse-I,-L,and-lflags;forexample,g -I/path/to/includemycode.cpp-L/path/to/lib-lmylibrary-omyprogramlinkslibmylibrary.

What is the volatile keyword in C What is the volatile keyword in C Sep 24, 2025 am 05:51 AM

The volatile keyword is used to prevent the compiler from optimizing variable operations and ensures direct access to memory every read and write. It is suitable for hardware registers, interrupt service programs, and signal processing scenarios.

What is the Rule of Three/Five in C What is the Rule of Three/Five in C Sep 23, 2025 am 06:08 AM

IfaC classdefinesadestructor,copyconstructor,orcopyassignmentoperator,itshouldalsodefinetheothertwo(RuleofThree);withC 11,addmoveconstructorandmoveassignmentoperator(RuleofFive)toproperlymanageresourcesandavoidundefinedbehaviorfromshallowcopiesordo

How to define a constant in C How to define a constant in C Sep 24, 2025 am 05:49 AM

Useconstforruntimeconstantswithtypesafety,likeconstintMAX_USERS=100;2.Useconstexprforcompile-timecomputation,suchasconstexprintBUFFER_SIZE=square(10);3.Avoid#defineduetolackoftypecheckingandscope,preferringconstorconstexprforbettercodequalityandmaint

How to set up a PowerShell development environment in VSCode How to set up a PowerShell development environment in VSCode Sep 23, 2025 am 02:12 AM

TosetupaPowerShelldevelopmentenvironmentinVSCode,installVSCodeandPowerShell7 ,theninstalltheofficialPowerShellextensionbyMicrosoftforsyntaxhighlighting,IntelliSense,debugging,andscriptanalysis,configureworkspacesettingslikeenablingprofileloadingandfo

See all articles