I am trying to write the following entire function to a text file while still maintaining its console output functionality without having code redundancy. Is there a simple way to post an entire method's result to a file and console at the same time?
#include<iostream>
#include<fstream>
void sports(){
cout<<"\nGame_Code\t\tGane\t\tCost\t\tStart Time\n";
cout<<"\nSP-9651\t\t Game 1 \t\t60\t\t08:00";
cout<<"\nSP-9652\t\t Game 2 \t\t60\t\t09:15";
cout<<"\nSP-9653\t\t Game 3 \t\t55\t\t09:55";
cout<<"\nSP-9654\t\t Game 4 \t\t55\t\t11:00";
cout<<"\nSP-9655\t\t Game 5 \t\t50\t\t13:00";
cout<<"\nSP-9657\t\t Game 7 \t\t45\t\t19:45";
cout<<"\nSP-9659\t\t Game 8 \t\t70\t\t22:45";
cout<<"\n\n";
}
int main(){
//This is for console output
sports();
}