用Linux写C++,不知道使用什么编辑器?VScode!

前置:

请确保你已经安装了g++gdb

安装VScode

详见ArchWiki,推荐yay -S visual-studio-code-bin

配置C++环境

首先安装C/C++拓展。

image

然后进入你的项目文件夹(我的是StudyCpp),创建launch.jsonsettings.jsontasks.json三个配置文件,如下:

image

launch.json

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "C/C++: g++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "",
        "args": [],
        "stopAtEntry": false,
        "cwd": "/home/yurlak/StudyCpp",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "C/C++: g++ build active file"
      }
    ]
  }

settings.json

{
    "files.associations": {
        "iostream": "cpp"
    },
    "C_Cpp.errorSquiggles": "disabled"
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++ 生成活动文件",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

将如上代码粘贴后开始写C++了!