C++ string中find() 用法

string中 find()的用法 rfind (反向查找) 
(1)size_t find (const string& str, size_t pos = 0) const;  //查找对象--string类对象
(2)size_t find (const char* s, size_t pos = 0) const; //查找对象--字符串
(3)size_t find (const char* s, size_t pos, size_t n) const;  //查找对象--字符串的前n个字符
(4)size_t find (char c, size_t pos = 0) const;  //查找对象--字符
结果:找到 -- 返回 第一个字符的索引
     没找到--返回   string::npos(代表 -1 表示不存在)
 
例子:
  std::size_t found = str.find(str2);
  if (found!=std::string::npos)  
    cout<<found<<endl;
 
posted @ 2017-02-21 20:13  he伟_li  阅读(43342)  评论(0编辑  收藏  举报