01-C++-VSCode配置C++环境(windows)

简介: 01-C++-VSCode配置C++环境(windows)

前言

  • 本篇来学习写使用VSCode配置C++环境

安装VSCode

  • 下载地址:VSCode
  • 下载后路next安装即可

安装mingw编译器

  1. 点击Files
  2. 向下拉,点击下载(建议windows64位直接下载8.1.0版本的x86_64-win32-seh或者x86_64-posix-seh)
  3. 解压上一步下载的压缩包,例如:解压到D盘
  4. 配置环境变量
  • 此电脑右键–> 属性
  • 高级系统设置 --> 环境变量

  • Paht中添加mingw64路径(需写到bin,如:D:\mingw64\bin)
  1. 验证配置是否成功
  • 打开cmd命令窗口,输入g++ -v

VSCode配置C++环境

  1. 新建一个文件夹(如:C++),用vscode打开文件夹
  2. 在C++文件夹下新建hello.cpp文件,写入如下代码
#include<iostream>
using namespace std;
int main(){
    cout<<"Hello,VScode!"<<endl;
    system("pause");
    return 0;  
}
  1. 按下CTRL+shift+P,调出面板,输入C/C++:Edit Configurations(UI)
  • 填写编译路径(上面安装的mingw64路径,如:D:\mingw64\bin\g++.exe)
  • IntelliSense mode里选择gcc-x64
  • 此时会发现左边多了一个.vscode文件夹,并且里面有一个c_cpp_properties.json的文件
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "D:\\mingw64\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
  1. 按下CTRL+shift+P,调出面板,输入Tasks:Configure Default Build Task

  • 再选择 C/C++:g++.exe build active file
  • 此时会在.vscode下出现一个tasks.json文件
{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: g++.exe build active file",
      "command": "D:\\mingw64\\bin\\g++.exe",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "D:\\mingw64\\bin"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "compiler: D:\\mingw64\\bin\\g++.exe"
    }
  ]
}
  • 运行代码验证配置
相关文章
|
2月前
|
JavaScript 前端开发 编译器
TypeScript教程(一)在vscode中的配置TypeScript环境
本文是一篇TypeScript入门教程,介绍了在VS Code中配置TypeScript环境的步骤,包括安装Node.js、使用npm安装TypeScript、配置npm镜像源、安装VS Code的TypeScript扩展,以及创建和运行一个简单的TypeScript "Hello World"程序。
TypeScript教程(一)在vscode中的配置TypeScript环境
|
21天前
|
JSON 数据格式
vscode配置latex
本文档介绍如何在VSCode中配置LaTeX环境。首先需安装texlive和VSCode,并提前安装SumatraPDF以查看PDF文件。配置包括设置自动编译、PDF预览程序及正反向搜索等。提供了详细的`settings.json`配置示例,涵盖不同操作系统下的编译选项与方案。此外,还介绍了如何配置SumatraPDF实现与VSCode的跳转功能,以及相关快捷键的使用方法。
|
2月前
|
C++ Python
VS Code 搭建 Python 环境 Conda管理
VS Code 搭建 Python 环境 Conda管理
38 2
|
2月前
|
Java 应用服务中间件 开发工具
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
|
2月前
|
网络安全 Windows
在Windows电脑上启动并配置SSH服务
在Windows电脑上启动并配置SSH服务
57 0
|
2月前
|
Ubuntu Linux 数据安全/隐私保护
在 Windows 中配置 WSL2 与 Debian 的全流程
【8月更文挑战第27天】本文详细介绍了在Windows环境中配置WSL2与Debian的全过程,包括确认Windows版本、启用相关功能、安装WSL并设置版本为WSL2、下载安装Debian、配置国内镜像源,以及设置Xserver实现GUI功能。通过这些步骤,用户能够顺利完成配置,并进行基本优化。
123 0
|
29天前
|
网络安全 虚拟化 Windows
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题
|
2月前
|
PHP Windows
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
|
2月前
|
开发框架 .NET API
Windows Server 2022 安装IIS 报错 访问临时文件夹 C:\WINDOWS\TEMP\3C 读取/写入权限 错误: 0x80070005
Windows Server 2022 安装IIS 报错 访问临时文件夹 C:\WINDOWS\TEMP\3C 读取/写入权限 错误: 0x80070005
81 0
|
2月前
|
Linux Docker Windows
Windows——Docker拉取Windows Server镜像
Windows——Docker拉取Windows Server镜像
110 0
下一篇
无影云桌面