在下面的代码片段中,短语std::string::npos是什么意思?
found = str.find(str2);
if (found != std::string::npos)
std::cout << "first 'needle' found at: " << int(found) << std::endl;发布于 2010-09-30 13:15:55
意思是找不到。
通常是这样定义的:
static const size_t npos = -1;最好与npos进行比较,而不是-1,因为代码更易读。
发布于 2010-09-30 13:18:05
string::npos是一个代表非位置的常量(可能是-1)。当找不到模式时,方法find会返回它。
发布于 2013-10-21 06:36:57
size_t是一个无符号变量,因此'unsigned value =- 1‘自动使其成为size_t:18446744073709551615的最大可能值
https://stackoverflow.com/questions/3827926
复制相似问题