Have you considered using std::filesystem instead of the fstream?