VSCode 配置C++环境并调成CLion风格

//2020.03.20更新
发现了更好用的自动补全插件(clang)。
先装个LLVM
把LLVM/bin添加到环境变量
安装vscode-clangd插件

VSCode 配置C++环境并调成CLion风格_第1张图片
现在试试补全的效果。(装了C++ Intellisense的可以卸了)
//默认你已经下好了vscode,并且电脑里有mingw(Dev CB里面都会有)

1、商店中搜索C++,下载(如下图)

VSCode 配置C++环境并调成CLion风格_第2张图片

2、商店下载Code Runner插件

VSCode 配置C++环境并调成CLion风格_第3张图片
Code Runner插件通过终端编译运行代码,因此需要将g++所在的目录添加到环境变量中
cmd下输入g++ -v检测是否添加成功

3、新建一个文件夹

在文件夹中创建c_cpp_properties.json,将以下代码写入

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "F:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

关键点是includePath的第二行:写入你自己的mingw对应的目录
到这一步已经可以通过右上角的小箭头编译运行C++了
但C++11的语法还不能用,因为编译选项在Code Runner的配置文件中

5、修改Code Runner配置文件

Ctrl + Shift + P打开settings.json
输入code-runner,会补全出一大串东西
将cpp的那行修改,加上c++14的编译选项-std=c++14:

"cpp": "clear cd $dir && g++ $fileName -std=c++14 -o $fileNameWithoutExt && $dir$fileNameWithoutExt"

其中clear是为了在编译后清屏,看起来更清爽

6、创建stdc++.h文件

平时常用#include ,但现在并不能用(不知道为啥)
解决方法就是在MinGW64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits目录下创建stdc++.h文件
将以下内容复制进去

// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// .

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include 
#endif
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#if __cplusplus >= 201103L
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#endif

// C++
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#if __cplusplus >= 201103L
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#endif

8、下载idea风格键盘映射

用惯了jetbrains家IDE的话直接下载即可
VSCode 配置C++环境并调成CLion风格_第4张图片

9、下载CLion主题

VSCode 配置C++环境并调成CLion风格_第5张图片
完美
VSCode 配置C++环境并调成CLion风格_第6张图片

你可能感兴趣的:(杂)