在此代码中string :: npos是什么意思? [英] What does string::npos mean in this code?

查看:101
本文介绍了在此代码中string :: npos是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码段中,短语 std :: string :: npos 是什么意思?

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

found = str.find(str2);

if (found != std::string::npos)
    std::cout << "first 'needle' found at: " << int(found) << std::endl;


推荐答案

这意味着找不到。

通常这样定义:

static const size_t npos = -1;

与npos相比而不是-1更好,因为代码更易读。

It is better to compare to npos instead of -1 because the code is more legible.

这篇关于在此代码中string :: npos是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆