string搜索操作
1. 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;
2. 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;
函数原型:
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 函数最容易出错的地方是和find函数搞混。它最大的区别就是如果在一个字符串str1中查找另一个字符串str2,如果str1中含有str2中的任何字符,则就会查找成功,而find则不同;