LoginSignup
13

More than 3 years have passed since last update.

VSCodeでC++のデバッグ時に標準入力を受け付ける方法

Posted at

MacのVSCodeでC++を初めて、デバッグの設定を行い実行できるようになったものの、標準入力がどこから入力していいのか分からず調査したのでメモ。

解決法

launch.json内にあるexternalConsoleオプションをtrueにすることで、標準入力を受け付けるコンソール画面(標準ではMaxの場合ターミナルアプリ)が起動し、そこから標準入力を入力することができるようになる。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true, // ここをtrueに変更する
            "MIMode": "lldb",
            "preLaunchTask": "build before debug"
        }
    ]
}

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13