Solve bits stdc-h file not found in macOS

Sometimes we run the c++ code in vs code (visual studio code) in macOS or Windows but show the message. Stdc++.h lib that includes all libs in c++

bits/stdc++.h’ file not found or fatal error: ‘bits/stdc++.h’ file not found  or sometimes #include bits/stdc++.h error

We can follow the steps to fix it :

MacOs

Step one :

brew install gcc

Check the gcc version

gcc --version

Step two :

go to InstalledDir path:

cd /Library/Developer/CommandLineTools/usr/bin
cd ../include

Step three :

sudo mkdir bits

Step Four :

Download this stdc++.h file. Download link

Step Five:

cd bits
sudo cp ~/Downloads/stdc++.h stdc++.h

Windows

If PC has installed already minGW

Copy this line

C:\MinGW\mingw32\lib\gcc\mingw32\4.8.1\include\c++\mingw32\bits

And paste it here

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include

Now check does it work to go to visual studio project and type bits and then choose stdc++.h

If the PC has not installed minGW:

Download this file first

Then go to go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include

Create a new folder name bits and paste there downloaded file

Now test the header

Openv vs code (visual studio code) and make a simple c++ project and test

#include<bits/stdc++.h>

The Advantages of bits/stdc++

  • It can reduce time wasted when starting coding especially when our rank matter
  • It helps to clean the header
  • We should not remember all types of c++ headers every time
  • It usually saves time when starting coding

Disadvantages of bits/stdc++

  • bits/stdc++.h is not a standard header for overall
  • Include lots of unnecessary headers in projects
  • If have time we can avoid it and write the necessary headers

Now easily you can compile.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *