C++string中find_first_not_of()函数和find_last_not_of()函数
C++string中find_first_not_of()函数和find_last_not_of()函数
在学习这两个函数之前建议先学C++string中find_first_of()函数和find_last_of()函数。
1、find_first_not_of()函数
正向查找在原字符串中第一个与指定字符串(或字符)中的任一字符都不匹配的字符,返回它的位置。若查找失败,则返回npos。(npos定义为保证大于任何有效下标的值。)
- string str=“abcdefab”;
- cout<<str.find_first_not_of(‘h’)<<endl;//第二个参数为0,默认从原串下标为0开始查找。第一个a就和带查字符不同,故输出a的下标0。<