C++ find_last_of function application example

#include <iostream>
#include <string>
using namespace std;
int main()
{
  string str1("as3dfa1sdfj1");
  string::size_type n1,n2,n3,n4;
  n1 = str1.find_first_of("0123456789",3);//从下标3开始往后查找,一直到结束
  n2 = str1.find_first_not_of("abcdefg",1);//从下标1开始往后查找,一直到结束
  n3 = str1.find_last_of("0123456789",4,3); //从下标4开始往前查找,"0123456789"的前3个字符最后一次出现的位置。注意第二个参数3表示查找“0123456789”的前三个字符
  cout << "n1 : " << n1 << endl;
  cout << "n2 : " << n2 << endl;
  cout << "n3 : " << n3 << endl;

  return 0;
}

 

Guess you like

Origin blog.csdn.net/digitalkee/article/details/108901257