您的位置:首页 > 编程语言 > C语言/C++

C++ Primer课后练习9.47

2016-12-07 18:51 323 查看
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;
}

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: