2
0

More than 1 year has passed since last update.

[mac][VSCode][C++] デバッグ実行時に標準入力を受け付ける方法

Last updated at Posted at 2022-07-17

競技プログラミング用の環境設定をしていたのですが、VSCodeのデバッグ実行時に標準入力を受け付ける設定でハマったのでメモを残します。

前提

設定済みの内容

以下ページを元に環境設定済み。ただし、デバッグ実行時に標準入力が使えない。
https://qiita.com/EngTks/items/ffa2a7b4d264e7a052c6

利用環境

  • OS: MacOS Monterey バージョン12.4
  • VSCode: Version: 1.51.1

どうやって解決したか

CodeLLDB(vadimcn.vscode-lldb)という拡張機能を入れて、これを使うようにしたら標準入力が使えるようになりました。

導入手順

1 拡張機能「CodeLLDB(vadimcn.vscode-lldb)」をinstall
2 launch.jsonを以下に書き換える

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": [
		{
			"type": "lldb",
			"request": "launch",
			"name": "Debug",
			"program": "${workspaceFolder}/${fileBasenameNoExtension}",
			"args": [],
			"cwd": "${workspaceFolder}",
			"preLaunchTask": "C/C++: g++ build active file"
		}
	]
}

3 tasks.jsonを以下に書き換える(既にこの内容になっている場合は書き換えなくてOK)

tasks.json
{
        "tasks": [
                {
                        "type": "cppbuild",
                        "label": "C/C++: g++ build active file",
                        "command": "/usr/local/bin/g++",
                        "args": [
                                "-g",
                                "${file}",
                                "-o",
                                "${fileDirname}/${fileBasenameNoExtension}"
                        ],
                        "options": {
                                "cwd": "${workspaceFolder}"
                        },
                        "problemMatcher": [
                                "$gcc"
                        ],
                        "group": {
                                "kind": "build",
                                "isDefault": true
                        },
                        "detail": "Task generated by Debugger."
                }
        ],
        "version": "2.0.0"
}

上記設定でC++のデバッグ実行時に標準入力が使えるようになりました
debug3.gif

追記

デバッグ実行時にvectorの中身を見れなかったのですが、tasks.jsonにて以下コンパイルオプションを追加することにより解決しました。

 "-gdwarf-3",
2
0
0

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
2
0