`
nepshi
  • 浏览: 49520 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

find和find_first_of的区别

 
阅读更多
find函数的声明:
size_t find ( const string& str, size_t pos = 0 ) const;
size_t find ( const char* s, size_t pos, size_t n ) const;
size_t find ( const char* s, size_t pos = 0 ) const;
size_t find ( char c, size_t pos = 0 ) const;

find_first_of函数的声明:
size_t find_first_of ( const string& str, size_t pos = 0 ) const;
size_t find_first_of ( const char* s, size_t pos, size_t n ) const;
size_t find_first_of ( const char* s, size_t pos = 0 ) const;
size_t find_first_of ( char c, size_t pos = 0 ) const;

find函数寻找完整匹配,find_first_of函数寻找任一匹配。
示例:
string line = "what_a_good_day_!";
line.find("_!");  //return 15
line.find_first_of("_!");  //return 4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics