Install gcc 11 using brew install gcc@11 in the terminal.
g++-11 --version and it should show g++-11 (Homebrew GCC 11.3.0) 11.3.0 or something similarInstall the Xcode app from App Store
Go to the path = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 To do this easily, open Finder and press Cmd+Shift+G and paste this path address and it should open up.
Create a folder named bits and go to this folder.
Create a file named stdc++.h inside the bits folder and open it using any text editor (e.g. TextEdit). So just right click on the stdc++.h file and select Open With and then select TextEdit.
Paste the content from this repo to the stdc++.h file: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/precompiled/stdc%2B%2B.h
Now close Sublime Text/VS Code and reopen it and run a C++ file.
My sublime build system for CP looks like this on Mac:
{
"shell_cmd": "g++-11 -std=c++17 \\"${file}\\" -o \\"${file_path}/${file_base_name}\\" && \\"${file_path}/${file_base_name}\\"<~/Desktop/Codes/input.txt>~/Desktop/Codes/output.txt && rm \\"${file_path}/${file_base_name}\\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c++",
}
~/Desktop/Codes/input.txt by the exact path of your input file and change ~/Desktop/Codes/output.txt by the exact path of your output file.
Check this to know how to get file paths on Mac.Make sure to install g++-11 using brew install gcc@11 . Run g++-11 --version to check if it is installed properly.
Now run the following code:
#include<bits/stdc++.h>
using namespace std;
int main() {
int x; cin >> x;
cout << x * x << '\\n';
return 0;
}
It should work!
If it shows: bash: g++-11 command not found but in the terminal g++-11 --version works fine, then in terminal run the which g++-11 command and it should return something like /opt/homebrew/bin/g++-11 . Then in the build change g++-11 by /opt/homebrew/bin/g++-11 .
path = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/include<cstdalign> is not found or smth similar. Just remove this include from the stdc++.h file and try again.stdc++.h:
include<cstdalign>include<cuchar>include<memory_resources>