>>OPERATORS << | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

>>OPERATORS <<

What is the purpose and use of >> << these operators in c++.

15th Feb 2017, 2:02 PM
Megatron
Megatron - avatar
8 Answers
+ 7
AFAIK, Shift left (<<) is used to shift the bit to left and similarly shift right (>>) is used to shift the bit to right. let us see a example. Consider 4<<1, Here 4 will be considered in bits i.e(100) so <<1 means shift the bit to left once, that will be 1000 which is 8 So 4<<1 = 8. I hope this helps.
15th Feb 2017, 2:29 PM
Mr.Robot
Mr.Robot - avatar
+ 7
No Maksym. You're wrong. <<,>> are shift left and shift right operators and being overloaded to cout and cin respectively.
15th Feb 2017, 2:24 PM
Mr.Robot
Mr.Robot - avatar
+ 2
@Maksym Zielinski I know that. But these are actually overloaded operator for the purpose you mentioned what is their use when they are not overloaded.
15th Feb 2017, 2:22 PM
Megatron
Megatron - avatar
+ 2
@Mr Robot Yes, That was what I searching for can you please explain their use.
15th Feb 2017, 2:25 PM
Megatron
Megatron - avatar
+ 2
cout and cin are objects of iostream and the operators are overloaded for the input and output function. Pay attention to the "." in other cin and cout commands. cin.getline() cout.write() cin.get()
15th Feb 2017, 2:26 PM
Megatron
Megatron - avatar
+ 1
Without overloading they are just bitwise operators
15th Feb 2017, 2:26 PM
Maksym Zieliński
Maksym Zieliński - avatar
0
>> when you put data into program << when you send data out of program
15th Feb 2017, 2:21 PM
Maksym Zieliński
Maksym Zieliński - avatar
0
And what cout and cin basically means? :)
15th Feb 2017, 2:25 PM
Maksym Zieliński
Maksym Zieliński - avatar