You are viewing a single comment's thread. Return to all comments →
Could someone help me understand what's happening with the line "cin >> curInput;"?
It's reading in a value from cin and assigning it to a previously declared variable named curInput. Each time the loop runs, it reads a variable value, assigns it to curInput, processes it accordingly, and then loops again until the loop is finished. Because the value of curInput is processed inside the loop and not needed again after processing, the value of curInput just gets overwritten at each cin >> curInput;.
cin >> curInput;
Ok, so it's not bitshifting? I thought the >> operator was for right bitshift, which is why I was so confused.
You are correct in that it is also the bitshift operator. C and C++ also use them as IO operators with cin and cout. my understanding as far as the reason for it is that they wanted to make the IO operators analagous to unix IO redirection operators.
Just a small aside - these IO operators were introduced in C++ - they don't exist in C.
Yes, C++ allows classes to redefine the basic operators for their own purposes. This feature is usually referred to as "operator overloading": https://isocpp.org/wiki/faq/operator-overloading#op-ov-benefits
So, the handling of ">>" when used with the istream class is customized for each possible argument type: http://www.cplusplus.com/reference/istream/basic_istream/operator%3E%3E/
Many people think that operator overloading reduces the comprehensibility of code. Perhaps for this reason, the designers of Java decided against allowing operators to be re-defined. (Even so, Java natively overloads the "+" operator for java.lang.String to concatenate rather than perform a mathematical operation.)
sorry but i did not understand this properly. Can you explain it clearly please? Thank you in advance.