Can you please provide more information. That being:
1.) What is the output of your code? Does it crash? or is it able to run succesfully but your print statements are unsuccesful?
2.) Do the print statements print only “Photon Position” and "Copy number: " or do they not print at all?
3.) The code sample which you have provided here, where in your code does it reside? Is it part of the G4UserSteppingAction?
Maybe related or maybe not, my program segfaults soon after, which is (also) a new behavior not observed (as far as I remember) on an older MacOS version. I would be surprised if this was directly causing the segfault, though, due to the if (step == NULL) check never triggering. But the segfault happens soon enough that I never see a second one of these print tests occur.
Finally I have checked that in a simple “hello world”-type c++ program compiled with g++ that printing with std::cout works as expected.
I think this was due to some conflicting conda environments, having built Geant4 in my standard env and my application in another. The issues (both printing and segfault) went away after completely building Geant4 in the proper env. I don’t know how that would have caused such a strange error, however.