I'm working on this piece of code where I am getting a holiday from my Holiday.txt
file and then inputting that holiday into my Schedule.txt
.
There are multiple holidays so I'm trying to loop through the file until it reaches the end and has fully copied them onto my second file, however it doesn't seem to be inputting the holiday into my string variable and I keep getting stuck in an infinite loop.
int main(){
fstream bookings("Schedule.txt");
fstream magicians("Magicians.txt");
fstream holidays("Holidays.txt");
string test;
string holiday;
bookings >> test;
testing to check if there's anything in bookings
if(test.length()==0){
while(!holidays.eof()){
getline(holidays, holiday);
bookings << holiday << endl << endl;
cout << "test";
}
}
return 0;
}
I've tried using different while loops including while(getline(holidays, holiday))
or even while(holidays >> holiday)
until they reach the end of the file but everything seems to get stuck in infinite loops.
Sorry if these are basic questions but I'm a beginner that's been trying to figure it out for so long now, even stepping through the program, and nothing seems to work. Can anyone explain to me what's going wrong?