I am programming a calculator that uses redirection (UNIX) ./calculator < expressions.txt to receive expressions from a file using a while loop in my main:
while(getline(cin, exp) ) {
try {
return the evaluated expressions
}
catch ( error ) { ... }
}
this works fine for me and returns the correct values. However, I also want my program to take in user input if a file is not redirected (It currently error outs and core dumps). How can I take in user input if a file is not provided and avoid the while loop.
Thank you.
stdin. If you execute the command just by itself, you will type./calculatorand then, provide the expression on next line. You can terminate the expression byctrl-D. Did you mean that you are trying to provide the filename as a command line parameter, such as./calculator expressions.txt?