string::npos在 c++ 的find_first_of判断是什么意思
2011-04-12 10:27
204 查看
string::npos的解释如下:
昨天写的逻辑判断,对find返回npos的意义理解的很模糊,查看了cpp primer后发现下面的内容,得知find方法返回一个名为 string::npos 的特殊值,说明查找没有匹配。粘上以备记忆.
The string
class provides six search functions, each named as a variant of find
. The operations all return a string::size_type
value that is the index of where the match occurred, or a special value named string::npos
if there is no match. The string
class defines npos
as a value that is guaranteed to be greater than any valid index.
string 类提供了 6 种查找函数,每种函数以不同形式的 find 命名。这些操作全都返回
string::size_type 类型的值,以下标形式标记查找匹配所发生的位置;或者返回一个名为 string::npos
的特殊值,说明查找没有匹配。string 类将 npos 定义为保证大于任何有效下标的值。
例如:
string str="http://www.my400800.cn
";
pos=str.find_first_of("www");
if(pos!=string::npos)
{
}
昨天写的逻辑判断,对find返回npos的意义理解的很模糊,查看了cpp primer后发现下面的内容,得知find方法返回一个名为 string::npos 的特殊值,说明查找没有匹配。粘上以备记忆.
The string
class provides six search functions, each named as a variant of find
. The operations all return a string::size_type
value that is the index of where the match occurred, or a special value named string::npos
if there is no match. The string
class defines npos
as a value that is guaranteed to be greater than any valid index.
string 类提供了 6 种查找函数,每种函数以不同形式的 find 命名。这些操作全都返回
string::size_type 类型的值,以下标形式标记查找匹配所发生的位置;或者返回一个名为 string::npos
的特殊值,说明查找没有匹配。string 类将 npos 定义为保证大于任何有效下标的值。
例如:
string str="http://www.my400800.cn
";
pos=str.find_first_of("www");
if(pos!=string::npos)
{
}
相关文章推荐
- string::npos在 c++ 的find_first_of判断是什么意思
- C++ 标准模板库学习之 string 类 详解 (一) 将一个句子中每个单词的单词字母顺序翻转 关于npos find_first_not_of find_first_of getline
- C++填坑之std::string::find_first_of
- C++中string.find()函数,string.find_first_of函数与string::npos
- string c++详解 find_first_not_of() find_first_of()
- string::npos 是什么 c++ /STL
- 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)
- std::string 类中find_first_not_of ()函数
- if (donutString.indexOf("dozen") != -1)是什么意思
- 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)
- C++ 11.2 accumulate、find_first_of 函数
- C++中std::string::find_last_of用法
- c++之STL(13) STL 算法 - 查找算法(4)find_first_of(b,e,sb,se) find_first_of(b,e,sb,se,bp)
- string 中的 find()、 find_first_of()、find_first_not_of()
- string 类成员函数 find() / find_first_of() / find_last_of() 的用法详解
- C++中string类的成员函数find_first_not_of()
- C++ 中string 的find与find_first_of 的区别?
- string类型中find和find_first_of
- (转帖)如何将字符串前后的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++)
- C++语句:vector<string>v_string;是什么意思?v_string代表什么?