1. sin >> line won't do anything since sin has nothing in it, so nothing will be put into line. Maybe you meant sin << line, but that is not legal for an istringstream. You should try it out.

BTW, now that I see the syntax highlighting, sin is perhaps not the best name since <cmath> has a sin function and even without using namespace std it is often exposed as just sin. I changed the name to iss in my code.

-----------------------------

2. The return value of sin >> ch is sin itself. That's why you can chain the calls like sin >> a >> b >> c, which is parsed as (((sin >> a) >> b) >> c). Each operator<< call returns sin so that it can be used in the next call.

When tested in a boolean context it return !sin.fail(), which is why it can be used to control a loop like while (sin >> ch). So in the if statements we're testing if the input failed (e.g., the input was letters or a number out of the range of the variable) before we test the more limited range.

-----------------------------

3(?) sin >> ch reads the first non-whitespace character it encounters. So if sin contained "John" it would read 'J".

sin.putback(ch) is just putting ch back into the stream so that the next sin>>?? call can read it again. It basically replaces your use of peek, except that peek will read the next char even if it's whitespace, whereas sin>>ch reads the next non-whitespace character, which we then put back so it can be read again.