How to include <bits/stdc++.h> file using clang++ compiler?

Hi, I am a student and I wanted to include <bits/stdc++.h> file in my code so that it will help me avoid including many files in my program to save time during competitive programming, but while including above file in my program, it gives error "file not found", since clang++ do not have it present by default, so I want to add it manually. Please help me fix the issue.

I already added bits folder at this location : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 following which I also created stdc++.h file but still error persists!!.

I also made bits folder with stdc++.h file at this location too : /Library/Developer/CommandLineTools/usr/include/c++/v1 but again couldn't fix the error!!

I also made respective changes in Homebrew folder (to fix it in g++ too, but again couldn't fix it!!)

Answered by DTS Engineer in 742364022

I already added bits folder at this location … but still error persists!

Don’t modify the Xcode toolchain. If you do that, your program will stop compiling the next time you update Xcode, won’t compile if you move it between machines, and so on.

Based on this answer it seems that this file is just a header that includes a whole bunch of headers. Personally, I don’t see that adding much value. However, if you want this then the easiest option is to create your own file, MyBits.h, that includes the headers you want to include and then, in each of your projects, add that file to the project and #include "MyBits.h" in your source code. That’ll be both reliable and portable.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I already added bits folder at this location … but still error persists!

Don’t modify the Xcode toolchain. If you do that, your program will stop compiling the next time you update Xcode, won’t compile if you move it between machines, and so on.

Based on this answer it seems that this file is just a header that includes a whole bunch of headers. Personally, I don’t see that adding much value. However, if you want this then the easiest option is to create your own file, MyBits.h, that includes the headers you want to include and then, in each of your projects, add that file to the project and #include "MyBits.h" in your source code. That’ll be both reliable and portable.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I'm a student too and I want to use vs code for competitive programming. But I'm using Mac so it's kind of hard for me to imbed #include bits/stdc++.h on my computer. After watching several videos and articles (which most of them turned out to be useless), I went to Finder, and I created a folder called "include" in my /usr/local folder, then I created another folder called "bits" in the "include" folder. Then I copied a document from GitHub that includes all the headsets I needed into the bits folder. But after I tried it on vs code, it still doesn't work. I'm so frustrated right now. Do you have a solution or any tips that you might want to share with me? I will be very grateful if you reply since all the videos and articles don't work for me.

I don’t understand your goal here. If you want to include a specific set of headers into your project, either:

  • Include them directly, or

  • Create your own MyBits.h file and include that.

That’ll work in any C / C++ environment. Why do you think you need to have <bits/stdc++.h> exactly?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi, I had the same issue months ago and I remember I didn't sleep that night until I fixed it.

Try creating the bits directory simply at this location:

/usr/local/include/

(usr is in MACINTOSH HD location)

The final location of the header should be: /usr/local/include/bits/stdc++.h

Also I recommend you MacVim for coding, it's way better than Xcode or Vscode for competitive programming. Xcode just takes a lot of space and for each cpp file it requieres a Project in order to compile, that's not comfortable (Months ago I also used to use Xcode).

CLion solution

  1. using finder go to /Library/Developer/CommandLineTools/usr/include/c++/v1
  2. make a folder called bits
  3. make a file called stdc++.h inside bits folder
  4. copy and paste content from https://github.com/tekfyl/bits-stdc-.h-for-mac/blob/master/stdc%2B%2B.h
  1. using finder go to /Library/Developer/CommandLineTools/usr/include/c++/v1

  2. make a folder called bits

Do not do this. The SDK installed by the Command Line Tools package is intended to be immutable. By modifying it you’re straying from the well-trodden path, which exposed to all sorts of weird pitfalls going forward.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How to include &lt;bits/stdc++.h&gt; file using clang++ compiler?
 
 
Q