Windows 平台下 VS Code 配置 C++ 环境与 UTF-8 全链路指南
本文介绍如何在 Windows 平台上,利用 VS Code 搭建高效的 C++ 开发环境,并彻底解决中文乱码问题。
一. 环境准备:安装 MinGW-w64 编译器
VS Code 本身是一个轻量级编辑器,需要外接编译器才能运行 C++。 PS: 网速问题可能需要关闭VPN
- 下载 MSYS2:前往 msys2.org 下载安装包。
- 安装工具链:安装完成后,打开
MSYS2 UCRT64终端,输入以下命令安装完整环境:pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
二. 配置系统环境变量
- bin文件夹(默认C:\msys64\ucrt64\bin)添加到PATH中
- CMD窗口验证: g++ –version
三. 配置全链路UTF-8
在 VS Code 中按下 Ctrl + Shift + P。
输入并打开 “首选项: 打开用户设置 (JSON)” (Open User Settings (JSON))。
在 JSON 中加入以下配置:
{ "terminal.integrated.profiles.windows": { "PowerShell": { "source": "PowerShell", "args": ["-NoExit", "-Command", "chcp 65001"] } }, "terminal.integrated.defaultProfile.windows": "PowerShell" }
PS:注意终端重启