必須の拡張機能
以下の拡張機能を VS Code にインストールします。
インストール後は VS Code を再起動します。
- CMake
- C++
- MinGW-w64
- 日本語 (簡体字)
MinGW-w64 のインストール
MinGW-w64 をダウンロードしてインストールします。
ダウンロードサイト:
https://sourceforge.net/projects/mingw-w64/files/
インストール時の選択肢:
- SJLJ: 32/64 ビット両方で使用可能ですが、性能に多少影響します。
- DWARF: 32 ビット専用。
- SEH: 64 ビット用の GCC 4.8 以降で推奨。
最新バージョンの MinGW-W64 GCC-8.1.0 をダウンロードします。
環境設定ファイル
compiler.json
コンパイラの設定を行います。
{
"configurations": [
{
"name": "Windows",
"includePaths": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerExecutable": "C:/mingw/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
debugger.json
デバッガの設定を行います。
{
"version": "0.2.0",
"configurations": [
{
"name": "gdb 起動",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "internalConsole",
"MIMode": "gdb",
"miDebuggerPath": "C:/mingw/bin/gdb.exe",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Pretty-printing を有効にする",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
builder.json
ビルドタスクの設定を行います。
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": "build"
}
]
}
プログラムの実行
プログラムを書いたら、保存し F5 キーを押します。