VS Code C++配置

环境准备

安装VSCode,安装常用插件
在这里插入图片描述
安装编译器,这里用TDM_GCC,安装后要添加到系统变量
在这里插入图片描述
添加后重启,否则可能出错!!
2020.1.23更:一次配置vscode的c++时,安装完TDM_GCC后可以直接右键运行hello world程序,无需配置.json文件
在这里插入图片描述

项目文件夹的创建

创建项目文件夹,新建一个.cpp文件
在这里插入图片描述
配置.vscode文件夹:
在这里插入图片描述
重点在于各个.json文件的配置,注意路径要和自己的路径相同
cc_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "C:/TDM_GCC/x86_64-w64-mingw32/include",
                    "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++",
                    "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward",
                    "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/tr1",
                    "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
                    "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "includePath": [
                "${workspaceFolder}",
                "C:/TDM_GCC/x86_64-w64-mingw32/include",
                "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++",
                "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward",
                "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/tr1",
                "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
                "C:/TDM_GCC/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64",

            "compilerPath": "gcc.exe"   
        }
    ],
    "version": 4
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "preLaunchTask": "build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/TDM_GCC/bin/gdb64.exe", // 这里修改GDB路径为安装的mingw64的bin下的gdb.exe路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "windows": {
                "command": "g++",
                "args": [
                    "-ggdb",
                    "\"${file}\"",
                    "--std=c++11",
                    "-o",
                    "\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
                ]
            }
        }
    ]
}

常用设置

ctrl+shift+p,输入setting,打开setting.json,设置如下:
在这里插入图片描述

文件切换后自动保存

“files.autoSave”: “onFocusChange”

滚轮调整字体:

“editor.mouseWheelZoom”: true

分号键格式化当前行代码:

“editor.formatOnType”: true

常用快捷键

自动排版 alt+shift+f

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值