vscode使用须知(cpp/c++)

安装

官网下载适合自己的安装包
准备好mingw64(可以自己在官网下载 或使用其他软件安装位置处的 比如DevC++,codeblocks)

安装后先汉化
打开下图的图标
在这里插入图片描述
在这里插入图片描述
搜索并下载安装图中标红扩展(其他扩展也可以根据需要安装)

下面就是要设置环境变量

一般是指在操作系统中用来指定操作系统运行环境的一些参数

右键我的电脑 点击属性

在这里插入图片描述
右侧高级系统设置
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
双击红色标记的path
在这里插入图片描述
选择新建 然后将 mingw64的绝对位置输进去(推荐C盘根目录 这种文件还不放在C盘 能放哪?)

接下来选择一个盘下的文件夹存放code(绝对路径必须无中文)

这个绝对路径可以在打开文件夹后的资源管理器界面右上搜索栏右边的栏点击一下显示

在这里插入图片描述
选择对应文件夹
在这里插入图片描述

在该文件夹下新建文件夹(使用上面方式新建文件夹)名称为.vscode
在此文件夹下新建四个文件 名称如下
在这里插入图片描述
里面的内容如下(有关路径需要自己调整 或者选择和作者一样的路径存放)

//c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "C:/Program Files (x86)/mingw64/include/**",
                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "${workspaceRoot}",
                    "C:/Program Files (x86)/mingw64/include/**",
                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
                ]
            }
        }
    ],
    "version": 4
}

//launch.json
{
    "version": "0.2.0",
    "configurations": [
    
        {
            "name": "C++ Launch (GDB)", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg", // 配置类型,这里只能为cppdbg
            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
            "targetArchitecture": "x86", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
            "program": "${file}.exe", // 将要进行调试的程序的路径
            "miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
            "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
            "cwd": "${fileDirname}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
            "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
        }
    ]
}
//settings.json
{
    // "workbench.colorTheme": "One Dark Pro",
    //"atomKeymap.promptV3Features": true,
    "editor.multiCursorModifier": "ctrlCmd",
    // "[cpp]": {
    //     "editor.quickSuggestions": true
    // },
    // "[c]": {
    //     "editor.quickSuggestions": true
    // },
    "files.associations": {
        "*.m": "matlab",
        "*.json": "jsonc",
        "*.cfg": "ini",
        "*.fsh": "glsl",
        "stack": "cpp",
        "iostream": "cpp",
        "ostream": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "exception": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "system_error": "cpp",
        "type_traits": "cpp",
        "typeinfo": "cpp",
        "utility": "cpp",
        "iomanip": "cpp",
        "complex": "cpp",
        "chrono": "cpp",
        "condition_variable": "cpp",
        "ctime": "cpp",
        "shared_mutex": "cpp",
        "cstring": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "bitset": "cpp",
        "cfenv": "cpp",
        "charconv": "cpp",
        "cinttypes": "cpp",
        "codecvt": "cpp",
        "csetjmp": "cpp",
        "csignal": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cuchar": "cpp",
        "deque": "cpp",
        "forward_list": "cpp",
        "list": "cpp",
        "unordered_map": "cpp",
        "unordered_set": "cpp",
        "vector": "cpp",
        "algorithm": "cpp",
        "functional": "cpp",
        "iterator": "cpp",
        "map": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "numeric": "cpp",
        "optional": "cpp",
        "random": "cpp",
        "ratio": "cpp",
        "regex": "cpp",
        "set": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "tuple": "cpp",
        "fstream": "cpp",
        "future": "cpp",
        "mutex": "cpp",
        "scoped_allocator": "cpp",
        "sstream": "cpp",
        "thread": "cpp",
        "typeindex": "cpp",
        "valarray": "cpp",
        "xstring": "cpp"
    },
    "editor.snippetSuggestions": "top",
    "C_Cpp.clang_format_sortIncludes": true,
    "editor.wordWrap": "on",
    "editor.formatOnPaste": true,
    "editor.formatOnType": true,
    "editor.codeActionsOnSaveTimeout": 500,
    "files.autoSave": "onFocusChange",
    "files.autoSaveDelay": 500,
    "editor.hover.delay": 0,
    "files.autoGuessEncoding": true,
    "editor.detectIndentation": false,
    "files.encoding": "utf8",
    "editor.formatOnSaveTimeout": 20,
    "editor.fontFamily": "Consolas",
    // "workbench.iconTheme": "vscode-icons",
    "fileheader.configObj": {
        "autoAdd": true, // 将该选项设置为true即可开启
    },
    "code-runner.runInTerminal": true,
    "C_Cpp.errorSquiggles": "Enabled"
}
//tasks.json
{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${file}.exe"
    ], // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "\\"
        ],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}
错误调试

使用自动生成的tasks.json很可能会导致出现无法解析不存在的文件
解决方案:
在task.json里

“fileLocation”: [“relative”, “${workspaceRoot}”],
改为
“fileLocation”: [“relative”, “\”],

修复鼠标悬停信息提示

解决方案:
重装有关插件

输出的中文为乱码

解决方案:
在这里插入图片描述
将底部修改为如图所示 utf-8----->GBK
点击红色位置
在这里插入图片描述
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值