在下面的代码片段中,短语std::string::npos是什么意思?
found = str.find(str2);
if (found != std::string::npos)
std::cout << "first 'needle' found at: " << int(found) << std::endl;发布于 2019-07-30 12:53:08
静态常量size_t npos = -1;
size_t的最大值
npos是一个静态成员常量值,对于size_t类型的元素,它具有最大的可能值。
当该值用作字符串的成员函数中的len (或sublen)参数的值时,表示“直到字符串结束”。
作为返回值,它通常用于表示没有匹配项。
此常量定义为值-1,因为size_t是无符号整数类型,所以它是此类型的最大可表示值。
https://stackoverflow.com/questions/3827926
复制相似问题