What does string::npos mean in this code?

后端 未结 12 1268
傲寒
傲寒 2020-11-30 18:50

What does the phrase std::string::npos mean in the following snippet of code?

found = str.find(str2);

if (found != std::string::npos)
    std::         


        
12条回答
  •  我在风中等你
    2020-11-30 19:31

    The document for string::npos says:

    npos is a static member constant value with the greatest possible value for an element of type size_t.

    As a return value it is usually used to indicate failure.

    This constant is actually defined with a value of -1 (for any trait), which because size_t is an unsigned integral type, becomes the largest possible representable value for this type.

提交回复
热议问题