Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The method of writing c language in vscode

Shulou Source: shulou.com Published: 2022-06-02 18:48:48 09月18日 Update

This article will explain in detail the method of writing c language in vscode. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1. Install vscode (version 1.27)

Https://code.visualstudio.com/ download and install vscode.

2. Install the cripple censor + extension.

3. Install the compilation tool mingw-w64, http://www.mingw-w64.org/doku.php/download

Configure environment variables. Take WIN10 as an example, this computer-Properties-Advanced system Settings-Environment variables-system variables-path- add a D:\ Program Files\ mingw-w64\ i686-8.1.0-posix-dwarf-rt_v6-rev0\ mingw32\ bin (you install the compiler tool path)

Before configuration

After configuration

-ps: if the environment variable is configured with vscode on, disable vscode and turn it on again after configuration.

4. Configuration file launch.json,task.json.

Create a new file hello.cpp

Press F5 to pop up to select the environment and configure launch.json

Click in, and the content in configurations: is as follows:

{"name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "enter program name, for example ${workspaceFolder} / a.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "/ path/to/gdb" "setupCommands": [{"description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing", "ignoreFailures": true}]}

Modify it as follows:

{"name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder} / a.exe", / / delete here and there enter program name, for example "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb" "miDebuggerPath": "D:\\ Program Files\\ mingw-w64\\ i686-8.1.0-posix-dwarf-rt_v6-rev0\\ mingw32\\ bin\\ gdb.exe", / / modify the path where you installed mingw32 "setupCommands": [{"description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing", "ignoreFailures": true}], "preLaunchTask": "build hello" / / name in task.json}

When you go back to hello.cpp, press F5 to pop up the error box and select the configuration task.

Click, then select Others, and task.json appears as follows:

"version": "2.0.0", "tasks": [{"label": "echo", "type": "shell", "command": "echo Hello"}]

The modifications are as follows:

"version": "2.0.0", "tasks": [{"label": "build hello", "type": "shell", "command": "command +", "args": ["- g", "hello.cpp",] "group": {"kind": "build", "isDefault": true}}]

Note: if it is a win32 program (window interface), add "- mwindows" to the args.

Go back to the hello.cpp file and press F5. The compilation ran successfully.

5. It is also found that the Chinese console shows garbled codes.

Just click utf-8 in the lower right corner.

Click Save with Code, select GBK, and then press F5 to run.

This is the end of the method of writing c language in vscode. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Configuration variables environment files compilation methods languages content tools more articles systems paths running good practical advanced success garbled tasks Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology vpn Linux Redmi