For an assignment, part of my program requires that I can receive 2 numbers from either a file or have them entered by hand. I can easily get them from a file by doing:
int n1,n2;
cin>>n1>>n2;
That way, a file with contents simply reading something like "7 13" will have the numbers read in just fine. However, my teacher wants us to have a format where we have a prompt before each number is entered, something that is handled like this:
int n1,n2;
cout<<"Number 1: ";
cin>>n1;
cout<<"Number 2: ";
cin>>n2;
However, using this code eliminates the ability to simply read the 2 numbers in from the file. How can I make it so that both methods work? I can't just combine them into one program because then I would have 2 of the same prompt. Is this even possible?
On a sidenote, I am having the numbers read in by typing on the command line: prog.exe < numberfile >