Skip to content

Instantly share code, notes, and snippets.

@rain1024
Last active June 2, 2022 23:09
Show Gist options
  • Save rain1024/1dc8b1c7992c0703e4a0ff5319375ed9 to your computer and use it in GitHub Desktop.
Save rain1024/1dc8b1c7992c0703e4a0ff5319375ed9 to your computer and use it in GitHub Desktop.

C++ 20 programming with Visual Studio Code (macOS Monterey)

Environment

  • C++ 20
  • macOS Montery
  • Visual Studio Code
  • Compiler: Clang++

Instructions

Step: Edit .vscode/c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Library/Developer/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/**"
            ],
            "compilerPath": "/Library/Developer/CommandLineTools/usr/bin/clang++",
            "cStandard": "c18",
            "cppStandard": "c++20",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Step: Edit .vscode/tasks.json

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "C/C++: clang++ build active file",
      "command": "/usr/bin/clang++",
      "args": [
        "-std=c++20",
        "-stdlib=libc++",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ]
}

Step: Edit .vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "lldb launch",
      "type": "lldb",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "preLaunchTask": "C/C++: clang++ build active file"
    }
  ]
}

Step: Add file main.cpp

#include <iostream>

using namespace std;

int main(){
  auto result = (10 <=> 20) > 0;
  cout << result << endl;
}

Press F5 to run, or click Run > Start Debugging

0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment