LoginSignup
21
17

More than 3 years have passed since last update.

Xcodeでbits/stdc++.hをインクルードする

Last updated at Posted at 2018-06-01

XcodeでC++を書いていて、#include <bits/stdc++.h>を使ったら'bits/stdc++.h' file not foundというエラーが出て、意外と詰まったので解決法を載せときます。私のようにターミナルの扱いにも慣れていない方向けに丁寧めに書きました。
未熟者なのでもっと良い方法あったら教えてください。

bits/stdc++.hとは

これはC++の標準ライブラリを一括でインクルードできるヘッダーファイルです。

#include <bits/stdc++.h>

と初めに書いておくだけで標準ライブラリが全て使えるようになります。
特に競技プログラミングではかなり便利です。

1. stdc++.hのダウンロード

ここからstdc++.hをダウンロードします。
https://gist.github.com/reza-ryte-club/97c39f35dab0c45a5d924dd9e50c445f

2. Xcodeのincludeフォルダに置く

あとはXcodeの標準ライブラリがあるフォルダに置くだけなのですがパーミッションやらのエラー対策も合わせて説明します。

まずターミナルでbitsフォルダを以下のディレクトリに作ります。

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1

cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1

mkdir bits

この時、Permission deniedと出てしまった場合はsudoを付けましょう。

sudo mkdir bits

そしてダウンロードしたstdc++.hをここに移動します。
stdc++.hが置いてあるフォルダに移動し、以下のコマンドを実行します。

mv stdc++.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/bits

これでXcodeで#include <bits/stdc++.h>を使ってもエラーが出ないようになりました。

参考

How can i include in xcode

もうPermission deniedなんて怖くない!〜linuxのパーミッションについてかなり丁寧に説明してみる〜

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