What does string::npos mean in this code?

后端 未结 12 1256
傲寒
傲寒 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:13

    std::string::npos is implementation defined index that is always out of bounds of any std::string instance. Various std::string functions return it or accept it to signal beyond the end of the string situation. It is usually of some unsigned integer type and its value is usually std::numeric_limits::max () which is (thanks to the standard integer promotions) usually comparable to -1.

提交回复
热议问题