现象:在Mac上使用VS Code调试C++代码时,无法使用scanf函数输入数据,程序卡在scanf函数那里。

为了解决这个问题,我们需要修改配置:

 按下组合键“⇧⌘D”弹出调试对话框,如下图操作

   Mac vscode C++调试 无法输入问题

 

 

 

  添加“launch.json”文件,如下图:

  Mac vscode C++调试 无法输入问题

 

无法接收调试控制台的输入,这里需要改一个地方:
launch.json

    "configurations": [
         {
            // 其他配置
           "externalConsole": true,
            "MIMode": "lldb"
        }
    ]

使得调试会新开控制台,但某些时候会出现新开控制台后卡住不动的问题,因为vscode没拿到控制台权限,这个时候需要:

 

  • 1、打开终端,输入:DevToolsSecurity -status检查是否为enabled,否则运行 
DevToolsSecurity -enable

Mac vscode C++调试 无法输入问题

  • 2、检查launch.json,不能出现
    "miDebuggerArgs":xxx
    "miDebuggerPath":xxx

 

3.按下组合键“⇧⌘B”,如下图操作

  Mac vscode C++调试 无法输入问题

  Mac vscode C++调试 无法输入问题

  Mac vscode C++调试 无法输入问题

  生成“tasks.json”文件:

Mac vscode C++调试 无法输入问题

  修改“tasks.json”文件,如下图:

  Mac vscode C++调试 无法输入问题

 

  • 3、task.json中添加一个配置项,内容如下
       {
           "label": "Open Terminal",
           "type": "shell",
           "command": "osascript -e 'tell application \"Terminal\"\ndo script \"echo hello\"\nend tell'",
           "problemMatcher": []
         }

再次按下组合键“⇧⌘P”,输入"Run Task":

Mac vscode C++调试 无法输入问题

 

 

 点击Open Terminal

Mac vscode C++调试 无法输入问题

 

 

点击OK!

Mac vscode C++调试 无法输入问题

 

 

 大功告成!enjoy!

      Unable to debug with ‘externalConsole’: true

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-10-16
  • 2021-12-02
  • 2021-06-23
  • 2021-09-16
  • 2021-12-15
猜你喜欢
  • 2021-11-03
  • 2021-07-24
  • 2022-12-23
  • 2021-06-15
  • 2021-12-06
  • 2021-04-28
  • 2021-10-16
相关资源
相似解决方案