Build. The generated executable file is stored in the project folder."/> Build. The generated executable file is stored in the project folder.">

Home  >  Article  >  Development Tools  >  How to run c++ code in sublime

How to run c++ code in sublime

下次还敢
下次还敢Original
2024-04-03 10:45:21728browse

Sublime 中运行 C++ 代码:安装 MinGW 或 Clang 编译器。创建 Sublime Text 项目。配置 MinGW:新建构建系统“C++ with MinGW.sublime-build”。配置 Clang:新建构建系统“C++ with Clang.sublime-build”。构建代码:按 Ctrl + B 或转到“工具”>“构建”。生成的可执行文件存储在项目文件夹中。

How to run c++ code in sublime

如何在 Sublime 中运行 C++ 代码

使用 MinGW 编译器

  1. 安装 MinGW:

    • 访问 MinGW 官方网站并下载适用于您操作系统的 MinGW 安装程序。
    • 安装 MinGW 并确保将其添加到系统路径中。
  2. 创建 Sublime Text 项目:

    • 打开 Sublime Text 并转到“File”>“New Project”。
    • 选择一个项目文件夹并输入项目名称。
  3. 配置构建系统:

    • 打开“Tools”>“Build System”>“New Build System”。
    • 输入以下内容并将其保存为“C++ with MinGW.sublime-build”:

      <code>{
        "cmd": ["g++.exe", "-std=c++17", "${file}", "-o", "${file_path}/${file_base_name}"],
        "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
        "selector": "source.c++, source.cpp"
      }</code>
  4. 运行代码:

    • 确保您的代码已正确保存。
    • Ctrl + B 或转到“Tools”>“Build”来构建代码。
    • 生成的可执行文件将存储在项目文件夹中。

使用 Clang 编译器

  1. 安装 Clang 和 LLVM:

    • 访问 LLVM 网站并下载适用于您操作系统的 Clang 和 LLVM 安装程序。
    • 安装 Clang 并确保将其添加到系统路径中。
  2. 创建 Sublime Text 项目:

    • 按照适用于 MinGW 编译器的步骤进行操作。
  3. 配置构建系统:

    • 创建一个名为“C++ with Clang.sublime-build”的新构建系统:

      <code>{
        "cmd": ["clang++", "-std=c++17", "${file}", "-o", "${file_path}/${file_base_name}"],
        "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
        "selector": "source.c++, source.cpp"
      }</code>
  4. 运行代码:

    • 按照适用于 MinGW 编译器的步骤进行操作。

The above is the detailed content of How to run c++ code in sublime. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn