search
HomeDevelopment ToolsVSCodeOne article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

How to develop C/C in VScode? How to configure the C/C environment? The following article will share with you the VScode configuration C/C operating environment tutorial (nanny-level teaching). I hope it will be helpful to everyone!

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Preparation work

Configure the C/C running environment in Vscode. First, you need to download C /C development environment, and then add the C/C development environment to the system variables.

The first step is to download vscode

Everyone should be able to download VsCode, but VsCode is not provided here. Download and installation tutorial

The second step is to download mingw

Here mingw is used as C/C Development environment, the official website link is as follows

Official website link:MinGW official website

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

After the download is completed, we will get such an installation Program [Recommended learning: vscode tutorial, Programming teaching, vuejs video tutorial]

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Double-click to open

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

##Then we Find the installation folder of mingw

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

##Enter
in sequence

mingw-get install gcc
  • mingw-get install g
  • mingw-get install gdb
Note

: Because the server that provides the download service is abroad, the download will be slow, and some content may not even be downloaded (such as gdb.exe). If you do not want to use gdb for debugging, gdb.exe does not have to be downloaded. Yes, (the run code is compiled and run directly, no gdb debugger is required)

If you want to use the gdb debugger, please refer to the msys2 installation method provided by the boss in the comment area Install the latest version
or download it from Baidu Netdisk (don’t ask why you use Baidu Netdisk, because other netdisks are full of T_T)

The version provided here is version 8.1.0 (the latest version 11.2, as of 2022 /11/14)
Link:
MinGW 8.1.0 version
Extraction code: Suif Compressed package size 129.41MB, use Baidu Netdisk for a limited time experience of 30s (if you still have If yes), it will be downloaded soon
Personal test, version 8.1.0 fully supports C 17 and below standards.

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]##Then mingw download is completed

The third step is to add mingw to the system variables#This step is to tell the computer in which folder the C/C running environment can be found

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

#In this way, our system environment is configured

We can check whether the configuration is correct
Press and hold win r to open In the following interface

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

enter cmd, then click OK


One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching] and enter
gcc -v
g -v
gdb -v
See if normal results are displayed

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching] If the results are displayed normally, it means that the system environment is configured correctly. At this time, it is recommended to restart the computer (of course, it is not necessary Restart)

The fourth step is to open VsCode and install the necessary plug-ins

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Our vscode configuration C/C preparation work is completed

Officially start the configuration

The first step is to create a new folder to store C/C files and create a new cpp file

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

We open that folder in vscode

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

##Then we can start configuring the environment

Note

: The configured environment is only applicable In this large folder

Configuration method 1 Configuration method with the help of run code plug-in-simple

This is the simplest configuration method, and it is also the most friendly method for beginners or people with little contact with computers.
This method requires the use of a plug-in, run code. Let’s first Open the extension store and install the run code plug-in



. After the installation is completed, we will find that there is an additional run codeOne article explains in detail vscode configuration C/C++ running environment [nanny-level teaching] on the right click.

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

# Just click run code to compile and run the program.

Problem 1: When run code runs the program, data cannot be entered into the terminal

Due to the settings of run code Problem, some students may get output results when using run code to run the program, but cannot directly input content into the program in vscode, so we need some settings to adjust the run code.

We press ctrl to enter settings (ctrl comma) or click File-> Preferences-> Settings

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

##Restart vscode so that we can enter content into the program in vscode

Question 2: run code An error of gcc (or g) :error; no such file or directory appears when executing the code

Cause analysis

This error may be caused by the compile command not being executed before Caused before entering the specified folder, so we can add a cd target folder path

Solution

One step to open the code runner extension settings

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

The second step is to enter the command setting interface

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

The third step is to modify the compilation instructions

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",

Configuration method 2 Configuration method using gdb debugging - complex

If you want to use the gdb debugger to debug the program, you need to use this method

The first step is to configure the editor environment

We hold down ctrl shift p to open the command panel or click View-> command Panel

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

We configure the compiler path and c/c standard

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Then close this interface, we will find that there is an additional .vscode folder in the CppProject folder

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

The second step is to configure task.json compilation task

Similarly, we hold down ctrl shift p to enter the command Panel or click View-> Command Panel

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

At this time we will find that there are more tasks.json## in the .vscode folder

# Briefly introduce what you need to pay attention to in tasks.json:

    label
  • : Compile the task name and configure launch.json afterwards We can call the compilation task by the compilation task name.
  • command
  • : Compiler path, the compilation task will call the compiler, please make sure the path is correct. args
    : Command transmitted to the compiler. By setting this content, you can set the path to generate the exe program

The third step is to configure the launch.json debugging task

Because the current C/C plug-in will not automatically generate launch.json, so launch .json needs to be written by ourselves. Create a new launch.json file in the .vscode folder

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

We will find that there is an added configuration

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

We click Add Configuration and select gdb to start

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

We Three places need to be modified

The first place: program - executable program path

  • This content indicates the called program path , its value should be the same as the path of the exe program generated in task.json, otherwise an error will be reported because the executable program cannot be found

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Second place: miDebuggerPath - Custom debugger path

  • This value represents the path of the gdb debugger. The value should be consistent with the path of the gdb debugger you want to use, otherwise it will prompt that the gdb debugger cannot be found

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

##The third place:

preLaunchTask - Compilation task executed before debugging

    This value indicates the compilation task used before starting the gdb debugger, and its value Equal to label in task.json.
  • This content is not automatically generated, so we need to write it manually.

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Save and restart the editor, we can press F5 to debug the program

Note: Any changes made to the file need to be saved before the new content will take effect. We can press ctrl s to quickly save the file

Question 1 Why is there no output result after running the program?

Q: Why does this error message appear after pressing F5 and there is no output result

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Answer: This is not an error message, but a compilation and debugging command, and the output results are displayed in the debugging console.

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

Advanced setting is the classic pop-up black window running program (in the system terminal Run the program in)

Some friends may find that the debugging console is not easy to use. If you want vscode to compile and run a c/c program, a terminal will pop up and run the program in the terminal. This Clicking is actually very simple. We only need to change the contents of program and args in launch.json, and then set the black window to pop up.

Q: Why not set it to run the program in the vscode built-in terminal?

Answer: Using gdb debugging with vscode does not provide configuration items for running programs in the built-in terminal of vscode.

    If you want to set up the program to run in the vscode built-in terminal, please refer to configuration method one or configuration method three

Note : Using the system terminal (cmd) to run the program cannot use breakpoint debugging, so please configure it as appropriate

It is not necessary for people like me who use vscode to write algorithm questions. breakpoint, so it is better to configure it to pop up a black window.

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

我的program 和 args 中的内容:

        "program": "C:\\Windows\\System32\\cmd.exe",
        "args": [
            "/c",
            "${fileDirname}\\build\\${fileBasenameNoExtension}.exe", // 更改这项内容为task.json中生成的exe程序路径就好
            "&",
            "pause"
        ],

完成后的效果
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

配置方法三 使用windows调试 - 比较复杂

有的小伙伴不想用run code,但是又想达到run code那样能在vscode内置终端中执行程序的效果,可以尝试下使用windows调试。(实际上就是只编译运行程序,没有任何辅助调试程序的功能)

注意:该配置方法无法使用断点调试。

第一步 配置编辑器环境

同配置方法二中的第一步

第二步 配置task.json 编译任务

同配置方法二中的第二步

第三步 配置launch.json 调试任务

先自建一个lanuch.json文件(参考配置方法二中的第三步)

  • 如果lanuch.json中有内容的话,先把configurations中的内容注释掉或者删除掉
  • 全选configurations中的内容,按下快捷键ctrl + / 即可快速注释选中内容。

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

然后我们点击添加配置,选择windows启动

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

我们只需要修改两项内容即可

第一处:program - 可执行程序路径

  • 该项内容表示调用的程序路径,其值应和task.json中生成的exe程序路径相同,否则会由于无法找到可执行的程序而报错

第二处:preLaunchTask - 调试之前执行的编译任务

  • 该项值表示启动gdb调试器之前使用的编译任务,其值等于task.json中的label。
  • 该项内容并不会自动生成,因此需我们手动编写。

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]
One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

注意配置项: console - 启动调试目标的位置

  • 通过更改该项的值,我们可以自由地切换在系统终端中运行程序还是在vscode终端中运行程序
  • 该项值为 externalTerminal 则是在系统终端中运行程序
  • 该项值为 integratedTerminal 则是在vscode终端中运行程序

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

我们把该项值改为 integratedTerminal 即可在vscode终端中运行程序

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

最终效果:

One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]

全篇结束,感谢阅读!如果有任何疑问可以评论区留言(因为水平有限,有些问题不一定能解答哈)!

编辑器插件推荐:

  • GitHub Theme: Theme plug-in, the editor theme shown in this article, Github Light pure white looks very comfortable.
  • vscode-icons: Icon plug-in, the icons shown in this article, with the icons, the sidebar looks more vivid.
  • codeSnap: A tool plug-in that generates code screenshots and is used to analyze the code. It is very nice.

For more knowledge about VSCode, please visit: vscode Basic Tutorial!

The above is the detailed content of One article explains in detail vscode configuration C/C++ running environment [nanny-level teaching]. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
How to format json with vscodeHow to format json with vscodeApr 16, 2025 am 07:54 AM

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).

How to compile vscodeHow to compile vscodeApr 16, 2025 am 07:51 AM

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.

How to install vscodeHow to install vscodeApr 16, 2025 am 07:48 AM

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.

How to enlarge fonts with vscodeHow to enlarge fonts with vscodeApr 16, 2025 am 07:45 AM

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 with vscodeHow to connect to a remote server with vscodeApr 16, 2025 am 07:42 AM

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

How to run vue with vscodeHow to run vue with vscodeApr 16, 2025 am 07:39 AM

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 two files with vscodeHow to compare two files with vscodeApr 16, 2025 am 07:36 AM

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 with vscodeHow to run js code with vscodeApr 16, 2025 am 07:33 AM

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).

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.