ofstream outPatron;
outPatron.open("patronRec.txt")
I am trying to make it so that all of my different functions within the class Patron can use this ofstream to write to a file which will contain all of the data for each patron. I have tried putting this code in the class definition, which leads to an error as such things can only be declared within functions. (or so I assume, considering that that's the only way I got it to work) I tried putting it inside a function definition within the class definition, and every time that function ran, it erased the entire file and started again with only the newest iteration. Finally, I tried putting this in main, but it wouldn't even compile, saying that each time I use outPatron in the class functions, it's an undeclared identifier. This is the function I need to use it in.
void Patron::AddPatron(string a, int b, int c, int d) {
SetName(a);
SetID(b);
SetFineBalance(c);
SetBooksOut(d);
count++;
outPatron << "Name: " << Patron::GetName() << endl;
outPatron << "ID: " << Patron::GetID() << endl;
outPatron << "Fine Balance: " << Patron::GetFineBalance() << endl;
outPatron << "Books Out: " << Patron::GetBooksOut() << endl << "-------------------" << endl;
}