How to adjust VSCode in Linux environment? The following article will share with you the VScode debugging tutorial and introduce the setting methods of tasks.json and launch.json. I hope it will be helpful to everyone!
Running environment:
VSCode 1.68.1
wsl: ubuntu subsystem
Without further ado, let’s start directly. First, select the fourth option on the left taskbar. [Recommended learning: vscode tutorial, Programming teaching]Running and debugging, click to create launch.json
The created interface is as shown in the picture above. Click Add Configuration in the lower right corner
As shown in the picture above, select the firstc/c (gdb) to start
At this time, the code shown in the picture above will be generated. Pay attention to the two places where I drew the arrows. The cwd is the working directory where our current file is located. Change the two places where I drew the arrows to be the same.
After the modification, it is as shown in the picture above. The a.out behind is the name of the executable file we will debug later. You can also use the one generated by the system here. Change it to your own That's fine, next we start configuring tasks.json
First go back to main.cpp, then click on the terminal in the menu bar above and select the last to configure the default Generate task
#At this time, as shown above, select the second c/c :g to generate the active file
As shown in the figure above, tasks.json is generated. Then we open launch.json to make a comparison. We first add a line of code "preLaunchTask" after launch.json. This line of code It means the name of the task that is run before launch. This name must be consistent with the task name in tasks.json. As shown in the figure below, the label in tasks.json must be exactly the same as the preLaunchTask in launch.json, because during execution Before launch.json, the system will first execute the contents of tasks.json based on this line of code. It can be simply understood that the code in tasks.json will help us compile and generate an executable file using g/gcc, and the code in launch.json It is to let the system debug our executable file.
Next, you will see the file in tasks.json, as shown in the figure below. The command configuration specifies the compiler, usually gcc or g compiler, and then The following args are the compilation options after the compiler. Note that -g means compiling an executable file with debugging information. If this -g is missing, the generated executable file cannot be debugged. The following main.cpp and swap.cpp is the name of the file to be compiled, the -0 parameter specifies the name of the generated executable file, the next line is the location of the generated executable file in the current working directory, the name is a.out
As shown in the figure below, everyone pays attention to the arrow part in the article. The two names must be the same. The one on the left is the generated executable file called a.out, and the one on the right is the debugging file called a. out, the name can be changed by yourself
So tasks.json is actually equivalent to helping us complete the operationg -g main.cpp swap.cpp -o a.out
After configuring the above files, go back to main.cpp to set your own breakpoint, and then press the F5 key to debug. Success
For more knowledge about VSCode, please visit: vscode Basic Tutorial!
The above is the detailed content of How to run and debug code in VScode? Tutorial sharing. For more information, please follow other related articles on the PHP Chinese website!

The ways to format JSON in VS Code are: 1. Use shortcut keys (Windows/Linux: Ctrl Shift I; macOS: Cmd Shift I); 2. Go through the menu ("Edit" > "Format Document"); 3. Install JSON formatter extensions (such as Prettier); 4. Format manually (use shortcut keys to indent/extract blocks or add braces and semicolons); 5. Use external tools (such as JSONLint and JSON Formatter).

Compiling code in VSCode is divided into 5 steps: Install the C extension; create the "main.cpp" file in the project folder; configure the compiler (such as MinGW); compile the code with the shortcut key ("Ctrl Shift B") or the "Build" button; run the compiled program with the shortcut key ("F5") or the "Run" button.

To install Visual Studio Code, please follow the following steps: Visit the official website https://code.visualstudio.com/; download the installer according to the operating system; run the installer; accept the license agreement and select the installation path; VSCode will start automatically after the installation is completed.

The methods to enlarge fonts in Visual Studio Code are: open the settings panel (Ctrl, or Cmd,). Search and adjust "Font Size". Choose "Font Family" with the right size. Install or select a theme that provides the right size. Use keyboard shortcuts (Ctrl or Cmd) to enlarge the font.

How to connect to a remote server through VSCode? Install Remote - SSH Extended Configuration SSH Create a Connection in VSCode Enter connection information: Host, Username, Port, SSH Key Double-click the saved connection in Remote Explorer

Running a Vue project in VSCode requires the following steps: 1. Install the Vue CLI; 2. Create a Vue project; 3. Switch to the project directory; 4. Install project dependencies; 5. Run the development server; 6. Open the browser to visit http://localhost:8080.

How to compare files in VSCode: 1. Open two files, 2. Enable the Differences view (View menu), 3. View the Differences (Add green, delete red, modify purple), 4. Use the arrow keys to navigate, 5. Accept or reject changes. Additional features include merging changes, copying changes, viewing details, and editing differences.

How to run JS code in VSCode? Create .js files and write code; install Node.js and npm; install Debugger for Chrome; open the debug console; select Chrome; add debug configuration; set debug scripts; run code; debug code (optional).


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor