Zapisanie obiektu klasy do pliku za pomocą fstream, a następnie odczytanie go

Chcę zrobić klasę ucznia i wziąć 3 informacje wejściowe i utworzyć wynik tego pliku. Jak to zrobić? To jest moja próba:

#include <iostream>
using namespace std;
class Student{
  private:
    char name[50];
    char id[50];
    int age;
  public:
    void getdata()
    {
        //take name as input
        //take id as input
        //take age as input
    }
    void showdata()
    {
         //display stored file
    }
 }

int main()
{
    Student s1;
    ofstream s1("student.txt");      //i want to store that 's1' object
    //anything else
    return 0;
}

questionAnswers(2)

yourAnswerToTheQuestion