Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"<< / >>" Operators in C++

So since I can't find anything on Google due to them somehow not accepting the search term ">>", I decided to ask here.

First of, no I do not mean the bitwise shift operator. This is different. I've seen it occur in some code and it would make no sense if it was a shift operator.

cout << a; would be an example. I know it prints out a, but what is the definition of "<<"?

Or in my case, I have a code similar to this:

for(int index=0;index<n;index++)
    inputFile >> StringArray[index];

What does it mean?

like image 311
spurra Avatar asked Apr 17 '26 00:04

spurra


1 Answers

The bitshift operator is frequently overloaded to mean reading values from and writing to streams.

Edit: In slightly more detail, C++ lets you overload, or change the meaning of, almost any operator. The << and >> operators were chosen to be overloaded for writing/reading to a source or sink of data because they visually look like arrows or conduits. There is zero commonality with shifting bits except as to what operator is used.

like image 185
yan Avatar answered Apr 18 '26 15:04

yan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!