LoginSignup
18
21

More than 1 year has passed since last update.

VisualStudioCodeで競技プログラミングの環境を作る(MacとC++)

Last updated at Posted at 2019-09-21

この手順は当時の環境構築時のものです。2023年2月現在はこの手順で構築できないようなので後日更新いたします。

PCを交換したので環境を構築します。
以下の記事を参考にさせていただきました。

Visual studio codeで競プロ環境構築[mac OS]
https://qiita.com/fuji_20/items/ffa2a7b4d264e7a052c6

CodeRunnerの出力をターミナルに出す方法[VSCode]
https://murabitoleg.com/vscode-runner/

##やること
homebrewのインストール
gccのインストール
VisualStudioCodeのインストール
環境整備

homebrewのインストール

ターミナルで実行
$ xcode-select --install

brewの公式ページからコマンドをコピペ

ターミナルで実行
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$brew --version
Homebrew 2.1.11
Homebrew/homebrew-core (git revision 0aa56; last commit 2019-09-21)

gccのインストール

ターミナルで実行
$ brew install gcc
$ ls -l /usr/local/bin/g++-9 
lrwxr-xr-x  1 kusakai  admin  29  9 21 12:33 /usr/local/bin/g++-9 -> ../Cellar/gcc/9.2.0/bin/g++-9
$ ln -s /usr/local/bin/g++-9 /usr/local/bin/g++
$ which g++
/usr/local/bin/g++
$ ls -l /usr/local/bin/g++
lrwxr-xr-x  1 kusakai  admin  20  9 21 12:24 /usr/local/bin/g++ -> /usr/local/bin/g++-9

VisualStudioCodeのインストール

Mac版をDLしてインストールする

環境整備

VisualStudioCodeを起動して、CodeRunnerとC/C++のプラグインをインストールする
image.png

CodeRunnerから実行した場合、標準入力を操作不可のため一部の設定を変更する。
「command ,」でSettingsを開き、「settings.json」を入力して「Edit in settings.json」をクリック
image.png

以下2行を追加する

settings.json
    "window.zoomLevel": -1,
+    "code-runner.clearPreviousOutput": true,
+    "code-runner.runInTerminal": true,

stdc++.hの場所移動

ターミナルで実行
$ ls -l /usr/local/Cellar/gcc/9.2.0/include/c++/9.2.0/x86_64-apple-darwin18/bits/stdc++.h 
-rw-r--r--  1 kusakai  staff  3213  8 12 16:58 $ /usr/local/Cellar/gcc/9.2.0/include/c++/9.2.0/x86_64-apple-darwin18/bits/stdc++.h
$ cd /usr/local/include/
$ cp /usr/local/Cellar/gcc/9.2.0/include/c++/9.2.0/x86_64-apple-darwin18/bits/stdc++.h .

これで準備できたので、動作確認として以下を動かします。

main.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a;
    cin >> b;
    cout << a + b << endl;
}

VisualStudioCode右上の再生ボタン(?)を押下(または右クリック→「Run Code」など)
image.png

想定通り動作してます。

18
21
2

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
18
21