08-find_first_of()系列
F.5.3 find_first_of()系列
find_first_of()方法的原型如下:
size_type find_first_of(const basic_string& str,
size_type pos = 0) const noexcept;
size_type find_first_of(const charT* s, size_type pos, size_type n) const;
size_type find_first_of(const charT* s, size_type pos = 0) const;
size_type find_first_of(charT c, size_type pos = 0) const noexcept;
这些方法与对应find()方法的工作方式相似,但它们不是搜索整个子字符串,而是搜索子字符串中的字符首次出现的位置。
string longer("That is a funny hat.");
string shorter("fluke");
size_type loc1 = longer.find_first_of(shorter); // sets loc1 to 10
size_type loc2 = longer.find_first_of("fat"); // sets loc2 to 2
在longer中,首次出现的fluke中的字符是funny中的f,而首次出现的fat中的字符是That中的a。