#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(int argc,char *argv[])
{
string s = "ab2c3d7r4e6";
string s1 = "1234567";
string s2 = "abcdefgr";
string::size_type pos=0;
while ((pos = s.find_first_of(s1,pos)) != string::npos)
{
cout << "第一个数字位置:" << pos << "数字为:" << s[pos] << endl;
++pos;
}
pos = 0;
while ((pos = s.find_first_of(s2,pos)) != string::npos)
{
cout << "第一个字母的位置:" << pos << "字母为:" << s[pos] << endl;
++pos;
}
return 0;
}
编写程序,首先查找string"ab2c3d7R4E6"中每个数字字符,然后查找其中每个字母字符。
最新推荐文章于 2021-07-01 16:33:58 发布