Skip to content

Commit 50f95ba

Browse files
committed
Add C project file
0 parents  commit 50f95ba

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "MinGW",
5+
"intelliSenseMode": "gcc-x64",
6+
"compilerPath": "C:\\RT\\msys64\\mingw64\\bin\\gcc.exe",
7+
"includePath": [
8+
"${workspaceFolder}/**"
9+
],
10+
"defines": [],
11+
"cStandard": "c11",
12+
"cppStandard": "c++17"
13+
}
14+
],
15+
"version": 4
16+
}

C-Project/.vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "(gdb) Launch",
9+
"type": "cppdbg",
10+
"request": "launch",
11+
"program": "${fileDirname}/build/${fileBasenameNoExtension}.exe",
12+
"args": [],
13+
"stopAtEntry": false,
14+
"cwd": "${workspaceFolder}",
15+
"environment": [],
16+
"externalConsole": true,
17+
"MIMode": "gdb",
18+
// 这里填你 MinGW-w64 安装目录下的 gdb 路径
19+
"miDebuggerPath": "C:\\RT\\msys64\\mingw64\\bin\\gdb.exe",
20+
"setupCommands": [
21+
{
22+
"description": "Enable pretty-printing for gdb",
23+
"text": "-enable-pretty-printing",
24+
"ignoreFailures": true
25+
}
26+
],
27+
// 这里要与你在 tasks.json 中配置的 label 一致
28+
"preLaunchTask": "compile",
29+
}
30+
]
31+
}

C-Project/.vscode/settings.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// 在终端中运行编译命令,否则我们无法与程序通过标准输入交互
3+
"code-runner.runInTerminal": true,
4+
// 如果你全局设置中的默认终端是 WSL 之类的,那么可以在工作区设置中改回 PowerShell
5+
//"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
6+
// 运行代码之前清除之前的输出
7+
"code-runner.clearPreviousOutput": true,
8+
// 开启这个后在运行编译命令之前会自动 cd 至文件所在目录
9+
"code-runner.fileDirectoryAsCwd": true,
10+
// 因为上面那个选项会自动 cd,所以我删除了默认编译命令中的 cd 语句
11+
// 同时我将编译结果的输出目录修改为了同目录下的 build 文件夹
12+
// 不然源码文件和编译结果混杂在一个目录中非常杂乱(尤其是刷题时)
13+
// 这里只保留了 C 和 C++ 的编译命令,有需要其他语言的请自行添加
14+
"code-runner.executorMap": {
15+
"c": "cls && gcc $fileName -o build/$fileNameWithoutExt && .\\build\\$fileNameWithoutExt",
16+
"cpp": "cls && g++ $fileName -o build/$fileNameWithoutExt && .\\build\\$fileNameWithoutExt",
17+
},
18+
// 运行代码后切换焦点至终端,方便直接输入测试数据
19+
"code-runner.preserveFocus": false,
20+
// 在运行代码之前保存文件
21+
"code-runner.saveFileBeforeRun": true,
22+
}

C-Project/.vscode/tasks.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "compile",
8+
"type": "shell",
9+
"command": "gcc",
10+
"args": [
11+
"-g",
12+
"\"${file}\"",
13+
"-o",
14+
"\"${fileDirname}\\build\\${fileBasenameNoExtension}\""
15+
],
16+
"presentation": {
17+
"reveal": "always",
18+
"panel": "shared",
19+
"focus": false,
20+
"echo": true
21+
},
22+
"group": {
23+
"kind": "build",
24+
"isDefault": true
25+
},
26+
"problemMatcher": {
27+
"owner": "cpp",
28+
"fileLocation": "absolute",
29+
"pattern": {
30+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(error):\\s+(.*)$",
31+
"file": 1,
32+
"line": 2,
33+
"column": 3,
34+
"severity": 4,
35+
"message": 5
36+
}
37+
}
38+
}
39+
]
40+
}

C-Project/test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int number = 666;
5+
char* string = "ads8f4sdfg15fsdg15re1g5sdf1";
6+
7+
printf("hello world: %d %s", number, string);
8+
return 0;
9+
}

0 commit comments

Comments
 (0)