Question: c++ create a A readevalprint loop hat takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user. You are
c++ create a A readevalprint loop hat takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user. You are NOT allowed to use fork, execve(2) (or the exec(3) family of functions), system(3), popen(3), and pclose(3)
Here are some examples (first line is a repl$ prompt that your program will literally print to standard output plus user input that your program will read in from the user; subsequent lines are output):
repl$ cat file.txt
Job STDIN = STDIN_FILENO Job STDOUT = STDOUT_FILENO Job STDERR = STDERR_FILENO
0 pipe(s) 1 process(es)
Process 0 argv: 0: cat 1: file.txt
repl$ cat file.txt | less
Job STDIN = STDIN_FILENO Job STDOUT = STDOUT_FILENO Job STDERR = STDERR_FILENO
1 pipe(s) 2 process(es)
Process 0 argv: 0: cat 1: file.txt
Process 1 argv: 0: less
repl$ cat file.txt | grep // > out.txt
Job STDIN = STDIN_FILENO Job STDOUT = out.txt (truncate) Job STDERR = STDERR_FILENO
1 pipe(s) 2 process(es)
Process 0 argv: 0: cat 1: file.txt
Process 1 argv: 0: grep 1: //
repl$ cat | grep // | less < in.txt >> out.txt
Job STDIN = in.txt Job STDOUT = out.txt (append) Job STDERR = STDERR_FILENO
2 pipe(s) 3 process(es)
Process 0 argv: 0: cat
Process 1 argv: 0: grep 1: //
Process 2 argv: 0: less
repl$ cat f1.txt f2.txt > out.txt e>> log.txt
Job STDIN = STDIN_FILENO
Job STDOUT = out.txt (truncate)
Job STDERR = log.txt (append)
0 pipe(s) 1 process(es)
Process 0 argv: 0: cat 1: f1.txt 2: f2.txt
repl$ echo "my \"cool\" shell" | less
Job STDIN = STDIN_FILENO Job STDOUT = STDOUT_FILENO Job STDERR = STDERR_FILENO
1 pipe(s) 2 process(es)
Process 0 argv: 0: echo 1: my "cool" shell
Process 1 argv: 0: less
repl$ cat file1 file2 file3
Job STDIN = STDIN_FILENO Job STDOUT = STDOUT_FILENO Job STDERR = STDERR_FILENO
0 pipe(s) 1 process(es)
Process 0 argv: 0: cat 1: file1 2: file2 3: file3
" | " distinguishes pipe " < " Job STDIN " > " Job STDOUT and if there is an 'e' infront of < or > Job STDERR
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
