0

What's the difference between << and >>

8th Oct 2017, 5:06 PM
Amogh Mishra
Amogh Mishra - avatar
2 Réponses
+ 13
In general, <<, means insertion operator and also bitwise left shift operator. >>, means extraction operator and also bitwise right shift operator. Examples string extract_from_stream = ""; cout << "Insert something into stream!"; cin >> extract_from_stream; int x = 5; // 0101 in binary x = x >> 1; // 0010 cout << x ; // 2 x = x << 1; // 0100 cout << x; // 4
8th Oct 2017, 5:17 PM
Babak
Babak - avatar
+ 2
'<<' is a left shift or stream output operator '>>' — right shift or stream input When used with streams, 'streamObject << someObject' puts 'someObject' on 'streamObject' stream; 'streamObject >> someVariable' — gets a value of someVariable's type from the streamObject stream, and puts it into someVariable. When used with numbers, '<<' performs binary shift left operation, '>>' — shift right.
8th Oct 2017, 5:21 PM
deFault