I am trying to allow a user to be able to read to a file once they selected any of the 2 case options. but it is giving me an error that says, "crosses initialization of std::ofstream"
#include <cstdlib>
#include<iostream>
#include<fstream>
#include<string>
#include<stdlib.h>
using namespace std;
main()
{
cout<<"Welcome to Blah High"<<endl;
string stud_passcode,staff_passcode;
int studdID,stafID;
char memopt;
cout<<"If you are a member of the student body select 1"<<endl;
cout<<"If you are a member of staff enter 2"<<endl;
cin>>memopt;
switch(memopt)
{
case 1:
ofstream staffIDO("StaffID.txt");
cout<<"Enter staff ID number"<<endl;
cout<<"Press Ctrl+Z to exit"<<endl;
while(cin >> stafID)
{
staffIDO<<stafID<<endl;
}
break;
case 2:
ofstream studID("student.txt");
cout<<"Enter student ID number"<<endl;
cout<<"Press Ctrl+Z to exit"<<endl;
while(cin >> studdID)
{
studID<<studdID<<endl;
}
break;
Default:
cout<<"Invalid option"<<endl;
}
}