search
HomeDevelopment ToolsVSCodeHow to write c language in vscode

How to write c language in vscode

1、安装vscode(版本1.27)

https://code.visualstudio.com/ 下载安装vscode。

2、安装c/c++扩展。

How to write c language in vscode

3、安装编译工具mingw-w64,http://www.mingw-w64.org/doku.php/download

配置环境变量,以WIN10为例 ,此电脑-属性-高级系统设置-环境变量-系统变量-path-添加一条D:\Program Files\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin(你安装编译工具路径)

配置前

How to write c language in vscode

配置后

How to write c language in vscode

-ps:如果开着vscode配置环境变量,配置完要关掉vscode重开一次。

4、配置文件launch.json,task.json。

新建文件hello.cpp,

How to write c language in vscode

按F5弹出选择环境,配置launch.json

How to write c language in vscode

点击进去,configurations:里内容如下:

{ 
"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 
} 
] 
}

修改成如下:

{ 
"name": "(gdb) Launch", 
"type": "cppdbg",
"request": "launch", 
"program": "${workspaceFolder}/a.exe",//这里删除前面那里的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",
//修改为你安装mingw32的路径 
"setupCommands": [ 
{ 
"description": "Enable pretty-printing for gdb", 
"text": "-enable-pretty-printing", 
"ignoreFailures": true 
} 
], 
"preLaunchTask": "build hello",//task.json里面的名字 
}

回到hello.cpp按F5弹出报错框,选配置任务。

How to write c language in vscode

点击,然后选Others,出现task.json,如下:

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

修改如下:

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

注意:如果是win32程序(窗口界面),args内加上"-mwindows"。

How to write c language in vscode

回到hello.cpp文件,按F5。成功运行编译。

How to write c language in vscode

5、还有就是发现中文控制台显示乱码。

How to write c language in vscode

只要点击右下角utf-8。

How to write c language in vscode

点击使用编码保存,选GBK,然后按F5运行。

How to write c language in vscode

PHP中文网,有大量免费vscode入门教程,欢迎大家学习!

The above is the detailed content of How to write c language in vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
How to debug vscodeHow to debug vscodeMar 06, 2025 am 11:20 AM

This article explains VS Code debugging, covering launch configurations, breakpoints, watch expressions, and the call stack. It details techniques like stepping through code, using conditional breakpoints, and inspecting variables. Troubleshooting

How to change the vscode languageHow to change the vscode languageMar 06, 2025 am 11:22 AM

This article explains how to change the Visual Studio Code display language. It details two methods: modifying the "Display Language" setting via the Settings UI or directly editing the settings.json file. The article also clarifies that

What is untracked in vscodeWhat is untracked in vscodeMar 06, 2025 am 11:18 AM

This article explains untracked files in VS Code's Git integration. It details how to identify, manage (adding, ignoring, deleting), and track these files using the GUI or command line, addressing why files become untracked.

How to delete vscode cacheHow to delete vscode cacheMar 06, 2025 am 11:17 AM

This article details methods for clearing the VS Code cache to improve performance and resolve issues. It outlines three approaches: deleting the cache folder (recommended), using developer tools, and reinstalling VS Code (last resort). Clearing th

How to downgrade vscodeHow to downgrade vscodeMar 06, 2025 am 11:21 AM

This article details how to downgrade Visual Studio Code. It explains the process of uninstalling the current version, downloading a previous release from GitHub, and reinstalling. Crucially, it emphasizes backing up settings and extensions before

Where to install the plug-in for vscodeWhere to install the plug-in for vscodeMar 06, 2025 am 11:14 AM

This article details VS Code extension installation locations (Windows, macOS, Linux), explains how to locate the directory using VS Code's command palette, and clarifies that the installation location cannot be changed. Reinstalling VS Code doesn'

How to delete vscodeHow to delete vscodeMar 06, 2025 am 11:15 AM

This article details how to uninstall Visual Studio Code (VS Code) across Windows, macOS, and Linux. It covers standard OS uninstall methods and manual cleanup of residual files and settings for a complete removal, emphasizing caution during manual

Which company is vscode fromWhich company is vscode fromMar 06, 2025 am 11:13 AM

This article examines Microsoft's Visual Studio Code (VS Code), highlighting its dual nature as a Microsoft-owned product with a significant open-source component. It details VS Code's key features (IntelliSense, debugging, Git integration, extensib

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!