What is the name of the "<<" and ">>" operators?
Solution 1
When not overloaded, left-shift and right-shift and some people call them that even when used with streams, but insertion and extraction is a lot more common in that context. They are also sometimes informally called put to and get from. IIRC, Stroustrup favoured that last form.
Solution 2
According to cplusplus.com's documentation:
This operator (<<) applied to an output stream is known as insertion operator.
...
And from the same website
This operator (>>) applied to an input stream is known as extraction operator.
...
Solution 3
In his book "The C++ Programming Language", C++11, bjarne stroustrup has called << "put to" and >> "get from".
Hope this helps
Solution 4
<<
is the insertion operator. Note when you write
cout << "Some text";
The arrows are pointing to the stream. You're inserting the text into the stream.
>>
is the extraction operator. When you write
cin >> some_var;
You're extracting a value from the stream.
Daniel R. Collins
Lecturer in Mathematics and Computer Science at CUNY/Kingsborough.
Updated on July 01, 2022Comments
-
Daniel R. Collins almost 2 years
I'm wondering if there is a standard name for the "<<" and ">>" operators? This is mostly in the context of teaching C++ and using those operators as part of stream input/output. If I need to read code or prompt for student responses (such as
cout << "Hello";
), I'm not sure how to verbalize those symbols. Is there a convention when reading them out loud?Improved version of this question: How do you read the "<<" and ">>" symbols out loud?
-
Daniel R. Collins over 7 yearsSo, for example: How would you verbalize
cout << "Hello";
? -
Daniel R. Collins over 7 yearsSo, for example: How would you verbalize
cout << "Hello";
? -
Jon Hanna over 7 years"Insert Hello to c-out", or "put Hello to c-out"
-
Joseph Sible-Reinstate Monica over 7 yearsI'd probably say ”write Hello to cout”.
-
Daniel R. Collins over 7 yearsSo: How would you verbalize cout << "Hello";?
-
Daniel R. Collins over 7 yearsI'm afraid this doesn't answer the question.
-
Daniel R. Collins over 7 yearsI'm afraid this doesn't answer the question.
-
Carcigenicate over 7 years"c-out some text". Since insertion is the most common you'll do on
cout
(at least in my experience), it's kind of implied. For a streams where both insertions and extractions are common, you might say "Insert/extract some text into/from the stream"