安装好 VsCode后,要下载安装 mingw64 或 msys2, 在win7上, vscode与msys2需要找旧版本才能装上.

VsCode v1.70.3 (win7最后一版): https://code.visualstudio.com/updates/v1_70
mingw64: https://www.mingw-w64.org/downloads/#mingw-builds
msys2的旧版:
https://github.com/msys2/msys2-installer/releases/tag/2022-10-28
下载 msys2-x86_64-20221028.exe
AutoVsCEnv_WPF V1.99 一键配置: https://github.com/SDchao/AutoVsCEnv_WPF/releases/tag/V.1995

  1. 安装插件
    1). C/C++ (作者: Microsoft)
    注: C代码智能提示, 右键菜单增加 Code Analysis 代码错误分析, 增加代码格式化
    2). Chinese (Simplified) (简体中文) Language Pack (作者: Microsoft)
    注: 这是中文语言包
    3). Error Lens (作者: Alexander)
    注: 这个优化错误信息显示
    4). Code Runner (作者: Jun Han)
    注: 让C / C++ 程序直接运行,菜单显示 "Run Code"
  2. 修改默认代码的编码为中文
    文件 - 首选项 - 设置 - 输入 encoding - 把下面的 UTF8 改为 Simplified Chinese
  3. 修改Code Runner 设置
    打 Code Runner 的扩展设置
    1) Code-runner: Clear Previous Output (清除上次的输出显示, 打勾)
    2) Code-runner: Default Language (默认编码, 填: GBK)
    3) Code-runner: Preserve Focus (保持焦点, 不打勾)
    指运行程序的时候,输入焦点是否保持在源代码,还是转到运行的程序里.
    4) Code-runner: Run In Terminal (是否在集成终端运行, 打勾)
    5) Code-runner: Save All Files Before Run (运行前先保存所有代码, 打勾)
    6) Code-runner: Save Files Before Run (运行前先保存代码, 打勾)
    7) Code-runner: Show Execution Message (是否显示运行信息, 不打勾)
  4. 修改 Code Runner 编译出来的 .exe 文件的存放目录
    Code Runner 的扩展设置 - Code-runner: Executor Map - 点 在settings-json 中编辑
    找到下面这2行:
    "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",

    改成如下:
    "c": "cd /D $dir && gcc $fileName -o .\bin\$fileNameWithoutExt && .\bin\$fileNameWithoutExt",
    "cpp": "cd /D $dir && g++ $fileName -o .\bin\$fileNameWithoutExt && .\bin\$fileNameWithoutExt",
    注: 上面的 cd /D $dir , 改变目录同跳转当前驱动器

然后,在你的代码文件夹下,建一个 bin 目录 (必须,否则编译出错)

  1. 关闭 运行C/C++文件
    只保存 code Run, 并闭: 调试C/C++文件, 运行C/C++文件
    在 C/C++ 的扩展设置, 搜 debug , 把 C_Cpp: Debug Shortcut 的勾去掉
    注: 如何要使用这2个入口运行代码,需要配置 .vscode\ 下面的 launch.json 和 tasks.json

cjc. 2024.10.14

标签: none

评论已关闭