How do you read the “<<” and “>>” symbols out loud?

混江龙づ霸主 提交于 2021-02-08 13:57:16

问题


I'm wondering if there is a standard way, if we are pronouncing typographical symbols out loud, for reading the << and >> symbols? This comes up for me when teaching first-time C++ students and discussing/fixing exactly what symbols need to be written in particular places.

The best answer should not be names such as "bitwise shift" or "insertion", because those refer to more specific C++ operators, as opposed to the context-free symbol itself (which is what we want here). In that sense, this question is not the same as questions such as this or this, none of whose answers satisfy this question.

Some comparative examples:

  • We can read #include <iostream> as "pound include bracket iostream bracket".
  • We can read int a, b, c; as "int a comma b comma c semicolon".
  • We can read if (a && b) c = 0; as "if open parenthesis a double ampersand b close parenthesis c equals zero semicolon".

So an equivalent question would be: How do we similarly read cout << "Hello";? At the current time in class we are referring to these symbols as "left arrow" and "right arrow", but if there is a more conventional phrasing I would prefer to use that.

Other equivalent ways of stating this question:

  • How do we typographically read <<?
  • What is the general name of the symbol <<, whether being used for bit-shifts, insertion, or overloaded for something entirely new?
  • If a student said, "Professor, I don't remember how to make an insertion operator; please tell me what symbol to type", then what is the best verbal response?
  • What is the best way to fill in this analogy? "For the multiplication operation we use an asterisk; for the division operation we use a forward-slash; for the insertion operation we use ____."

回答1:


Saw this question through your comment on Slashdot. I suggest a simpler name for students that uses an already common understanding of the symbol. In the same way that + is called "plus" and - is (often) called "minus," you can call < by the name "less" or "less-than" and > by "greater" or "greater-than." This recalls math operations and symbols that are taught very early for most students and should be easy for them to remember. Plus, you can use the same name when discussing the comparison operators. So, you would read

std::cout << "Hello, world!" << std::endl;

as

S T D colon colon C out less less double-quote Hello comma world exclamation-point double-quote less less S T D colon colon end L semicolon.

Also,

#include <iostream>

as

pound include less I O stream greater

So, the answer to

"Professor, I don't remember how to make an insertion operator; please tell me what symbol to type."

is "Less less."

The more customary name "left/right angle bracket" should be taught at the same time to teach the more common name, but "less/greater" is a good reminder of what the actual symbol is, I think.

Chevron is also a neat name, but a bit obscure in my opinion, not to mention the corporate affiliation.




回答2:


My comment was mistaken (Chrome's PDF Reader has a buggy "Find in File" feature that didn't give me all of the results at first).

Regarding the OP's specific question about the name of the operator, regardless of context - then there is no answer, because the ISO C++ specification does not name the operators outside of a use context (e.g. the + operator is named "addition" but only with number types, it is not named as such when called to perform string concatenation, for example). That is, the ISO C++ standard does not give operator tokens a specific name.

The section on Shift Operators (5.8) only defines and names them for integral/enum types, and the section on Overloaded Operators does not confer upon them a name.

Myself, if I were teaching C++ and explaining the <</>> operators I would say "the double-angle-bracket operator is used to denote bitshifts with integer types, and insertion/extraction with streams and strings". Or if I were being terse I'd overload the word and simply say "the bitshift operator is overloaded for streams to mean something completely different".

Regarding the secondary question (in the comment thread) about the name of the <</>> operators in the context of streams and strings, the the C++14 ISO specification (final working-draft: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf ) does refer to them as "extractors and inserters":

21.4.8.9 Inserters and extractors
template<class charT, class traits, class Allocator>
basic_istream<charT,traits>&
operator>>(
   basic_istream<charT,traits>& is,
   basic_string<charT,traits,Allocator>& str
);

(and the rest of the >> operator overload definitions follow)

This is further expanded upon on 2.7.2.2.2:

27.7.2.2.2 Arithmetic extractors
operator>>(unsigned short& val);
operator>>(unsigned int& val);
operator>>(long& val);

(and so on...)




回答3:


A proposal: Taking the appearance of the insertion/extraction operators as similar to the Guillemet symbols, we might look to the Unicode description of those symbols. There they are described as "Left-pointing double angle quotation mark" and "Right-pointing double angle quotation mark" (link).

So perhaps we could be calling the symbols "double-left angle" and "double-right angle".




回答4:


cout << "string" << endl;// I really just say "send string to see out. Add end line."
i++;  // i plus plus
auto x = class.func() // auto x equal class dot func
10 - ( i %4) * x;  // ten minus the quantity i mod four times x
stdout // stud-out
stderr // stud-err
argc   // arg see 
argv   // arg vee
char*   // char pointer
&f     // address of f



回答5:


  1. Just because it's an "extraction" or an "insertion" operator does not mean that is the OPERATION.
  2. The operation is "input" and "output"
  3. They are stream operators.
  4. The natural label would be c-out stream output double-quote Hello world exclamation double-quote stream output endline
  5. This the OPERATION you are doing (the verb)
  6. What the ARM calls the operator is irrelevant in that it is a systemic way of looking at things and we are trying to help humans understand things instead


来源:https://stackoverflow.com/questions/42775451/how-do-you-read-the-and-symbols-out-loud

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!