CR的代码文本

all for learning about the world
  订阅 订阅  :: 管理

find()和find_first_of()

Posted on 2009-11-20 12:48  mumuliang  阅读(1074)  评论(0编辑  收藏  举报

std::string chars = "abcd";
std::string str = "0123a5678abcd";

str.find(chars)的值是9
str.find_first_of(chars)的值是4

解释
find()是从str 中查找第一次完全匹配于 chars 的位置。
find_first_if() 是从str 中查找匹配于 chars 中任一字符的位置。此时的chars 更多的像一个用来匹配的字符的集合,而不是一个字符串。