There have been several posts elsewhere related to this topic. I experienced the same problem.
Some of the answers appear to me to be mumbo-jumbo -- the answers may indeed work around the issue but do not explain the cause of the problem (eg deleting old SDKs, using the command line tools infrastructure, reinstalling from HomeBrew..).
The only solution which worked for me is the one outline above: using
-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
The -isystem command line argument is not described in the man pages on my ssystem (Sequoia 16.4) although it does seem to be documented at certain places online.
Surely this is a bug in Xcode's compile? How is it that the compiler cannot figure out, when compiling C++ code, that the C++ includes need to be queries before those from the standard C library. And how is that Apple's man page is deficient?