I'm trying to make a simple shell program, and looking at a few examples, most people use getline () to enter input, however I try to use read () and noticed a strange error that other people saw or knew the reason.
When I run the code using getline, everything works fine. After starting the program, I get the name of the terminal that will be displayed, and it is ready to accept input. When I use reading, it seems to execute the shell name after entering the input. This seems to be happening no matter what I do. string to display shell name
cout << "SweetShell-> ";
and then AFTER this line, I either start the read command, or even call another process, which then starts the read command, and in any case, printing "SweetShell->" occurs AFTER input.
Even during testing, I had a block of code like:
cout << "SweetShell-> "; int test = read(0,buf,MAX_ARGS); //temp is a string that is set to the input cout << temp << " " << test;
and the result looked something like this:
3SweetShell-> ls
means he printed spaces, then tested, then first cout and finally temp. Does anyone know what is happening with this?
c ++ order order-of-operations
Someonerandom
source share