The file is distributed with GCC. You install GCC with Macports or Homebrew.
Answer from Matteo on Stack Exchangebrew install gcc
The file is distributed with GCC. You install GCC with Macports or Homebrew.
brew install gcc
Here are the steps that I followed, if someone is still looking for an answer.
brew install gccgcc --version- cd to InstalledDir path:
cd /Library/Developer/CommandLineTools/usr/include
- create bits directory in there. use sudo if permission issues
sudo mkdir bits
- copy
stdc++.hlink in bits directory, in my case I downloaded it in Downloads.cd bitssudo cp ~/Downloads/stdc++.h stdc++.h
This was enough for the compiling.
c++ - How can I include <bits/stdc++> in Xcode - Stack Overflow
Why so many students are using '#include<bits/stdc++.h>' instead of '#include<iostream>'?
Won't compile with clang: <bits/stdc++.h> not found
c++ - ERROR: <bits/stdc++.h>, 'cstdalign' file not found, running C++17 - Stack Overflow
Videos
You can do it by copying stdc++.h file from here: https://gist.github.com/reza-ryte-club/97c39f35dab0c45a5d924dd9e50c445f
Then you can include the file in your c++ file like this:
//suppose the file is in your home folder, here my username is reza
#include "./stdc++.h"
Since, bits/stdc++ is a GNU GCC extension, whereas OSX uses the clang compiler.
You have to create bits directory inside /usr/local/include and then make a header file stdc++.h inside bits and paste the contents of this gist inside it. Then, it should compile as expected.
Since, /usr directory is hidden by default on Mac OSX.
- Open Finder.
- Click Go on menu bar then click Go to folder or Press Command+Shift+G directly.
- Enter the path /usr/local/include
- Now proceed as mentioned above.
(UPDATE: For latest OS X you need to make folder include inside local and make bits folder inside include folder and then copy paste the code inside bits folder.)
I am hiring for my company. And the codes submitted for a test problem has '#include<bits/stdc++.h>' at the beginning. The MacOS default compiler complains
main.cpp:1:9: fatal error: 'bits/stdc++.h' file not found
#include<bits/stdc++.h>
^~~~~~~~~~~~~~~
1 error generated.
Why people are using '#include<bits/stdc++.h>'?
#include<bits/stdc++.h> is an internal header for the GCC and you are not supposed to use it, it's not portable.
remove the #include<bits/stdc++.h>
instead write #include<vector> and #include<iostream>
also remove using namespace std it considered bad practice
so you code should look like this:
#include <vector>
#include <iostream>
int main()
{
// Create an empty vector
std::vector<int> vect;
vect.push_back(10);
vect.push_back(20);
vect.push_back(30);
for (int x : vect)
std::cout << x << " ";
return 0;
}
I was having the same issue. First I installed gcc via homebrew
brew install gcc
To avoid conflict with the existing gcc (and g++) binaries, homebrew names the binary suffixed with version. At time of this comment, the latest was gcc-10.
You dont have to copy the bits/stdc++.h after this. Just compile using g++-<major-version-number> instead of g++, which would use the homebrew installed binary instead of the default osx one. For me it is
g++-10 -Wall -O2 -std=c++11 test.cpp -o test
To check the binary name that homebrew installed you can look in the /usr/local/bin directory because thats where homebrew installs packages.
Also, make sure that usr/local/bin is before /usr/bin in your $PATH