VScode配置C/C++语言环境(下)

本文详细介绍了如何在VSCode中配置C/C++开发环境,包括创建文件夹结构、下载并安装必要的插件(如C/C++CompileRun、CodeRunner等),以及配置`.vscode`文件夹中的c_cpp_properties.json、launch.json和tasks.json。指导读者如何编写并运行第一个C语言项目‘hello.c’。
摘要由CSDN通过智能技术生成

 

一、创建你以后用来写C/C++的

 

文件夹:

小编直接在桌面上做了一个做演示:code文件夹下有 .vscode、C、C++ 三个子文件夹。

注意vscode前有个.vscode(这个文件夹必须有,下面的“.json”文件都保存在这个文件夹里)

da9d1d4f9ef94bfca9f210499eeb0c9b.gif

 


二、下载必备的扩展:

C/C++的插件

1、C/C++ Compile Run

235167fffc0d456498e7214a025884fc.png

2、C/C++(可以把上面三个都下了,哈哈)

7ab438fd00e14bf6983d700aa3c1bff3.gif

 3、Code Runner

dfdd04e67348428fbd5008e60efd0412.png

4、Language Support for Java(TM) by Red Hat

d5433011df4a43f8a40189a73e2ec002.png


三、.vscode文件夹中的文件:

1、在vscode中打开桌面上刚刚建的文件夹code

24e1941a58424d9ca7197cf4ac849ac9.gif

2、在 .vscode 下创建以下文件 (源码在下面)

如果在上期MinGW安装路径是和小编一样的代码直接复制,

和小编不一样的就要修改 “c_cpp_properties.json” 、“launch.json” 、“tasks.json”中关于路径的代码

1、c_cpp_properties.json

2、launch.json

3、settings.json

4、tasks.json

(1)、c_cpp_properties.json

{
    "configurations": [
      {
        "name": "Win64",
        "includePath": ["${workspaceFolder}/**"],
        "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
        "windowsSdkVersion": "10.0.18362.0",
        "compilerPath": "C:/Mingw/MinGW/bin/gcc.exe",
        "cStandard": "c17",
        "cppStandard": "c++17",
        "intelliSenseMode": "gcc-x64"
      }
    ],
    "version": 4
  }

(2)、launch.json

{
"version": "0.2.0",
  "configurations": [
      {
          "name": "g++.exe",
          "type": "cppdbg",
          "request": "launch",
          "program": "C:\\Windows\\System32\\cmd.exe",
          "args": ["/c","${fileDirname}\\coin\\${fileBasenameNoExtension}.exe","&","pause"],
          "stopAtEntry": false,
          "cwd": "${fileDirname}",
          "environment": [],
          "externalConsole": true,
          "MIMode": "gdb",
          "miDebuggerPath": "C:\\Mingw\\MinGW\\bin\\gcc.exe",
          "preLaunchTask": "C/C++: g++.exe",
          "setupCommands": [
              {
                  "description": "gdb",
                  "text": "-enable-pretty-printing",
                  "ignoreFailures": true
              },
              {
                  "description": "Intel",
                  "text": "-gdb-set disassembly-flavor intel",
                  "ignoreFailures": true
              }
          ]
      }
  ]
}

(3)、settings.json

{
    "files.associations": {
      "*.py": "python",
      "iostream": "cpp",
      "*.tcc": "cpp",
      "string": "cpp",
      "unordered_map": "cpp",
      "vector": "cpp",
      "ostream": "cpp",
      "new": "cpp",
      "typeinfo": "cpp",
      "deque": "cpp",
      "initializer_list": "cpp",
      "iosfwd": "cpp",
      "fstream": "cpp",
      "sstream": "cpp",
      "map": "c",
      "stdio.h": "c",
      "algorithm": "cpp",
      "atomic": "cpp",
      "bit": "cpp",
      "cctype": "cpp",
      "clocale": "cpp",
      "cmath": "cpp",
      "compare": "cpp",
      "concepts": "cpp",
      "cstddef": "cpp",
      "cstdint": "cpp",
      "cstdio": "cpp",
      "cstdlib": "cpp",
      "cstring": "cpp",
      "ctime": "cpp",
      "cwchar": "cpp",
      "exception": "cpp",
      "ios": "cpp",
      "istream": "cpp",
      "iterator": "cpp",
      "limits": "cpp",
      "memory": "cpp",
      "random": "cpp",
      "set": "cpp",
      "stack": "cpp",
      "stdexcept": "cpp",
      "streambuf": "cpp",
      "system_error": "cpp",
      "tuple": "cpp",
      "type_traits": "cpp",
      "utility": "cpp",
      "xfacet": "cpp",
      "xiosbase": "cpp",
      "xlocale": "cpp",
      "xlocinfo": "cpp",
      "xlocnum": "cpp",
      "xmemory": "cpp",
      "xstddef": "cpp",
      "xstring": "cpp",
      "xtr1common": "cpp",
      "xtree": "cpp",
      "xutility": "cpp",
      "stdlib.h": "c",
      "string.h": "c"
    },
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "terminal.integrated.profiles.windows": {
      "PowerShell": {
          "source": "PowerShell",
          "icon": "terminal-powershell",
          "args": [
              "-NoLogo",
              "-NoExit",
              "-Command",
              "chcp.com 65001"
          ]
      },
      "Command Prompt": {
          "path": [
              "${env:windir}\\Sysnative\\cmd.exe",
              "${env:windir}\\System32\\cmd.exe"
          ],
          "args": [
              "/K",
              "chcp 65001"
          ],
          "icon": "terminal-cmd"
      }
  },
    "aiXcoder.showTrayIcon": true,
    "files.encoding": "gbk",
    "files.autoGuessEncoding": true
  }

(4)、tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "g++",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-fexec-charset=GBK"
            ],
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            },
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 生成活动文件",
            "command": "C:\\Mingw\\MinGW\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\coin\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

最后:(文件图标与小编不一样也不会有影响)

5895e27ce82c4fb5b44f233b9ad96b3a.png

 


四、创建第一个C语言项目“hello.c”:

如图所示:现在用F6和F8运行程序

493a8dafa1e04683b57a08736dba12ee.gif

#include <stdio.h>
int main() {
    printf("Hello World!\n");
    return 0;
}

用F6或F8打印一下 (用鼠标点击代码任意行,再按F6或F8运行)

45a8ca04e088449eb7cc76f6c944238b.gif

 

 或者点击代码任意行,右击鼠标,Run Code

 

dc53f351e1f84e939d4fa01031426f26.gif

 

点击小编头像,主页有上。

注:小编好像忘记了,找不到g++的,点击vscode桌面图标>鼠标右键>属性>兼容性>以管理员身份运行。

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值