VS code配置C/C++编译环境并支持C++11语法

最近看到好多同学说自己在VScode中写代码总是因为环境问题出错,主要是不支持c++11语法特性的问题。我就把我的VScode的json配置贴上来。

我当前的配置解决的是Linux环境下C/C++编译环境及支持C++11语法特性问题

我的环境:centos 7.5(之前一直用Ubuntu,最近白嫖了个腾讯云服务器)

平时写代码主要是用VScode,远程连接到Linux服务器上运行。 强烈建议还在Window环境下玩的同学能够转到Linux下来玩,可以和我一样在本地Windows下用vscode远程ssh到Linux服务器上玩。

在最左边的扩展中搜索C/C++ 和code runner进行安装

VS code配置C/C++编译环境并支持C++11语法_第1张图片

下面这是我的几个json配置文件,这都是在.vscode目录下的

VS code配置C/C++编译环境并支持C++11语法_第2张图片

c_cpp_properties.json文件

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

 launch.json文件

    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ 生成活动文件",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

tasks.json文件

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ 生成活动文件",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-std=c++11",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

settings.json文件

这个我只要是为了方便一键编译代码,主要是默认编译命令不支持c++11特性  下面第5行cpp部分后面加了-std=c++11

{
    "code-runner.executorMap": {

        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -std=c++11 && $dir$fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "python -u",
        "perl": "perl",
        "perl6": "perl6",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash",
        "fsharp": "fsi",
        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "scheme": "csi -script",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runhaskell",
        "nim": "nim compile --verbosity:0 --hints:off --run",
        "lisp": "sbcl --script",
        "kit": "kitc --run",
        "v": "v run",
        "sass": "sass --style expanded",
        "scss": "scss --style expanded",
        "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
        "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
    },
    "files.associations": {
        "*.cpp": "cpp",
        "sstream": "cpp",
        "iosfwd": "cpp",
        "iostream": "cpp",
        "array": "cpp",
        "string": "cpp",
        "list": "cpp",
        "ostream": "c",
        "stdio.h": "c",
        "cmath": "cpp",
        "cstdlib": "cpp",
        "vector": "cpp",
        "*.tcc": "cpp",
        "deque": "cpp",
        "unordered_map": "cpp",
        "type_traits": "cpp",
        "fcntl.h": "c",
        "unistd.h": "c",
        "functional": "cpp",
        "algorithm": "cpp",
        "numeric": "cpp",
        "memory": "cpp",
        "initializer_list": "cpp",
        "utility": "cpp"
    }
}

这样我可以直接F5一键编译运行代码

VS code配置C/C++编译环境并支持C++11语法_第3张图片

以上就是我的json文件,同学有需要的可以贴到自己的vscode中,我之前主要的问题还是针对c++11的问题将json文件修改。

你可能感兴趣的:(环境问题,vscode,c++编译环境,支持c++11语法,Linux环境,vscode,json文件)