自留 iOS配置VSCODE的C++环境

暂时并没有卵用的官方文档:https://code.visualstudio.com/docs/cpp/config-clang-mac

 

大佬博客网址:https://blog.csdn.net/u010358894/article/details/106755533

 

=================自己的备份(和大佬的内容几乎一样,不一样的标蓝了)=========================

推荐安装插件

Bracket Pair Colorizer 2 (强烈推荐)
C/C++ (必须安装)
Chinese (Simplified) Language Pack for Visual Studio Code (可选)
Code Runner (强烈推荐)
CodeLLDB (必须安装)
 

配置文件

在工作目录中新建.vscode文件夹, 然后进入该文件夹分别新建如下名称文件:

1.launch.json

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "clang++ - Build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": true,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true, // 调用Mac自带终端
      "MIMode": "lldb",
      "preLaunchTask": "clang++ build active file"
    }
  ]
}

2.tasks.json

{
  "version": "2.0.0",
  "tasks": [
      {
          "type": "shell",
          "label": "clang++ build active file",
          "command": "/usr/bin/clang++",
          "args": [
              "-std=c++17",
              "-stdlib=libc++",
              "-g",
              "${file}",
              "-o",
              "${fileDirname}/${fileBasenameNoExtension}"
          ],
          "options": {
              "cwd": "/usr/bin"
          },
          "problemMatcher": "$gcc",
          "group": {
            "kind": "build",
            "isDefault": true
          },
          "presentation": {
            "echo": true,
            "reveal": "always", 
            "focus": false,     
            "panel": "new"   // 可选为shared, 但编译会提示终端被任务重用, 建议设置为new
        },
      }
  ]
}

3. settings.json

{
    "files.defaultLanguage": "c++", // 输入分号(C/C++的语句结束标识)后自动格式化当前这一行的代码
    "editor.suggest.snippetsPreventQuickSuggestions": false, // clangd的snippets有很多的跳转点,不用这个就必须手动触发Intellisense了
    "editor.acceptSuggestionOnEnter": "on", // on: 回车自动补全 off: tab自动补全
    // "editor.snippetSuggestions": "top", // (可选)snippets显示在补全列表顶端,默认是inline

    "code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法输入
    "code-runner.executorMap": {
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt.out -Wall -O2 -std=c11 && ./$fileNameWithoutExt.out",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt.out -Wall -O2 -std=c++17 && ./$fileNameWithoutExt.out"
    }, 
    "code-runner.saveFileBeforeRun": true, // run code前保存
    "code-runner.preserveFocus": false,     // 若为false,run code后光标会聚焦到终端上。如果需要频繁输入数据可设为false
    "code-runner.clearPreviousOutput": false, // 每次run code前清空属于code runner的终端消息,默认false
    "code-runner.ignoreSelection": true,   // 默认为false,效果是鼠标选中一块代码后可以单独执行,但C是编译型语言,不适合这样用

    "C_Cpp.clang_format_sortIncludes": true,
    "editor.formatOnType": true, // 格式化时调整include的顺序(按字母排序)
}

4.c_cpp_properties.json
与windows下不同, mac下似乎必须设置该项, 按shift+command+p, 选择C/C++: Edit Configurations (UI), 按下图设置并保存自动生成c_cpp_properties.json.

我操作的时候,按shift+command+p, 选择C/C++: Edit Configurations (UI)

之后就会自动生成c_cpp_properties.json文件

(生成的c_cpp_properties.json文件长这样

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ], // 建议先安装xcode, 该项可以自动生成
            "compilerPath": "/usr/bin/clang",
            "intelliSenseMode": "clang-x64",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

然后环境就配置完了!

在这个环境下可以建立.cpp文件去运行啦,也可以在这个文件夹下建立文件夹,然后文件夹里放.cpp代码,都是可以的

只要代码在这个大的文件夹(如下图文件夹所示,就是在"C++环境"这个文件夹里写代码(try.cpp)或者建文件夹ttt (文件夹ttt中写ttt.cpp文件)都是在这个环境里的~)

感觉就是像是创了个环境文件夹,emmmm

文件夹VScode中的结构长这样:

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值