LoginSignup
5
6

More than 3 years have passed since last update.

【C++】MacのVScode上で.cppファイル読み取り&コンパイル → 実行 まで (拡張機能)

Last updated at Posted at 2020-02-20

はじめに

備忘録・理解目的。
おかしいところ等あればご指摘いただけるとありがたいです(^_^;)

環境

・ Mac OS Catalina: v10.15.3
・ VScode: v1.42.1
・ C/C++: v0.26.3
・ Code Runner: v0.9.15
 
表示させたいコード(ハローワールド)

helloworld.cpp

#include <iostream>

using namespace std;

int main(){
  cout << "Hello World!" << endl;
  return 0;
}

手順

C/C++ extension for VS Code のインストール

VScode拡張機能としてExtentionから「 C/C++ extension for VS Code 」をインストール。

Code Runner のインストール

同じくExtentionから「 Code Runner 」をインストール。

実行 & 結果

コード画面右上に表示される 「 」 をクリックするとコンパイルされて別ファイル(↓)ができ、VScodeのターミナルで実行される。

����    �      �  ��!     ...

 
実行結果


[Running] cd "ファイルパス" && g++ helloworld.cpp -o helloworld && "ファイルパス"helloworld
Hello World!

[Done] exited with code=0 in 1.362 seconds

コマンド・ショートカット 等

・起動
 「 Ctrl 」 + 「 Alt 」 + 「 N 」

・停止(読み取り表示のみのため、実行中はctrl+C、killコマンドができない
 「 Ctrl 」 + 「 Alt 」 + 「 M 」

参考

Run C++ Code in macOS Visual Studio Code! (2019)
Visual Studio CodeでC/C++プログラミング
Visual Studio Codeにてコードを実行することができる拡張機能

5
6
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
5
6