Reference Book: 《C++ Primer》
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
P327练习9.47:编写程序,查找string中的每个数字字符,然后查找其中每个字母字符。第一个用find_first_of,第二个用find_first_not_of。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string numbers("0123456789"), name("ab2c3d7R4E6");
string::size_type pos = 0;
while((pos = name.find_first_of(numbers, pos)) != string::npos)
{
cout << "Found first number at index: " << pos
<< " element is " << name[pos] << endl;
++pos;
}
pos = 0;
while((pos = name.find_first_not_of(numbers, pos)) != string::npos)
{
cout << "Found first character at index: " << pos
<< " element is " << name[pos] << endl;
++pos;
}
}