Saving and Loading a file

Hi. I am trying to make a billing file in C++. I was going okay till I encountered saving and loading step. I am trying to save a file(with file extention .txt) using switch statement.
When the input is 6, it will goes to the save(). I have been using istream &operator>> to input datas, and ostream &operator<< to output inputs. How is the saving function should be? And also, at the end of save(), it should display how many billing datas were there(if there were 3 files, should display 3 files were saved). After this, it has to load the saved data(s).
Will someone please help me, as I am an amateur in C++ programming. Thank you very much.

switch (Menu()) {
case 1: cin >> b;
cin >> eb;
cout << eb;
break;
case 2: cin >> b;
cin >> gb;
cout << gb;
break;
case 3: cin >> b;
cin >> tb;
cout << tb;
break;
case 4: eb.setElecRates();
break;
case 5: gb.setGasRates();
break;

case 6:
{
//Save
ofstream fout;
cout << "Text file name:";
getline(cin, fileName);
fout.open(fileName.c_str());
fout << eb << gb << tb;
int counter=0;
if (!fout.eof()){
bool flagg=true;
if (eb.GetAmDue()){
counter+=1;
if (gb.GetAmDue()){
counter+=1;
if (tb.GetAmDue()){
counter+=1;
}
}
}
}
cout << endl << "6 bills have been saved." << endl;
fout.close();
}
case 7:
{
//Load
ifstream fin;
cout << "Text file name:";
getline(cin, fileName);
fin.open(fileName.c_str());
while (fin.good())
{
cout << "Loaded!" << endl;
cout << fin << endl;
}
fin.close();
}
break;
Topic archived. No new replies allowed.