9.47
#include
#include
using namespace std;
int main(void)
{
string s1("ab2c3d7R4E6");
string s2("23746"), s3("abcdRE");
string::size_type pos = 0;
while ((pos = s1.find_first_of(s2,pos)) != string::npos)//find_first_of找数字
{
cout << "found number at index: " << pos
<< " element is " << s1[pos] << endl;
++pos;
}
pos = 0;
while ((pos = s1.find_first_of(s3, pos)) != string::npos)//find_first_of找字母
{
cout << "found letter at index: " << pos
<< " element is " << s1[pos] << endl;
++pos;
}
pos =0;
while ((pos = s1.find_first_not_of(s2, pos)) != string::npos)//find_first_not_of找字母
{
cout << "found letter at index: " << pos
<< " element is " << s1[pos] << endl;
++pos;
}
pos = 0;
while ((pos = s1.find_first_not_of(s3, pos)) != string::npos)//find_first_not_of找字母
{
cout << "found number at index: " << pos
<< " element is" << s1[pos] << endl;
++pos;
}
}