#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "ab2c3d7R4E6";
string numbers { "1234567890" };
string letter{ "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" };
string::size_type pos = 0;
while ((pos = str.find_first_of(numbers, pos)) != string::npos)
{
cout <<str[pos]<<"\tat index of element\t"<< pos << endl;
pos++;
}
cout << "\n------------------------------------------------\n";
string::size_type lpos = 0;
while ((lpos = str.find_first_of(letter, lpos))!= string::npos)
{
cout << str[lpos] << "\tat index of element\t" << lpos<<endl;
lpos++;
}
cout << "\n*******************另一种方法***********************\n";
pos = 0;
while ((pos = str.find_first_not_of(letter, pos)) != string::npos)
{
cout << str[pos] << "\tat index of element\t" << pos << endl;
pos++;
}
cout << "\n------------------------------------------------\n";
lpos = 0;
while ((lpos = str.find_first_not_of(numbers, lpos)) != string::npos)
{
cout << str[lpos] << "\tat index of element\t" << lpos << endl;
lpos++;
}
}
```
9.38 C++primer 第四版 习题9.38
最新推荐文章于 2022-09-03 13:37:04 发布