64,637
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
using namespace std;
int main() {
char str[] = "uu123aaa3435ddd9989a1";
char tmp[32];
size_t i = 0;
vector<int> vInts;
char* p = str;
while (true) {
if (isdigit(*p)) {
tmp[i++] = (*p);
}
else {
if (i) {
tmp[i] = 0;
vInts.push_back(atoi(tmp));
}
i = 0;
}
if (!(*p)) {
break;
}
++p;
}
for (i = 0; i < vInts.size(); ++i)
cout<<vInts[i]<<endl;
return 0;
}
//cout<<newstring<<endl;
for(i=0;i<j;i++)
cout<<newstring[i];
#include <iostream>
#include <string>
using namespace std;
int main()
{
char *p="hello123world";
int i,j;
int len=strlen(p);
char *newstring =new char[len+1];
memset(newstring,0,sizeof(newstring));
for(i=0,j=0;i<len;i++)
{
if(isdigit(p[i]))
newstring[j++]=p[i];
}
cout<<newstring<<endl;
return 0;
}