Does an empty string contain an empty string in C++?

后端 未结 7 1348
渐次进展
渐次进展 2021-01-03 00:53

Just had an interesting argument in the comment to one of my questions. My opponent claims that the statement \"\" does not contain \"\"<

7条回答
  •  时光说笑
    2021-01-03 01:25

    It depends on what you mean by "contains".

    The empty string is a substring of the empty string, and so is contained in that sense.

    On the other hand, if you consider a string as a collection of characters, the empty string can't contain the empty string, because its elements are characters, not strings.

    Relating to sets, the set

    {2}
    

    is a subset of the set

    A = {1, 2, 3}
    

    but {2} is not a member of A - all A's members are numbers, not sets.

    In the same way, {} is a subset of {}, but {} is not an element in {} (it can't be because it's empty).

    So you're both right.

提交回复
热议问题