C++实现查找字符串中的数字,并输出

例如输入:dsafjoi3425sfsdjl5435asfkl--=3400
输出为:3425 5434 3400

#include
#include
using namespace std;
void findnum(string & ch);
bool isnum(char n);
int main()
{
string m ;
cout << "Enter a string:\n";

while (cin>>m&&cin.get() != '\n');

findnum(m);

return 0;
}

void findnum(string & ch)
{
int k = ch.size();
int* num = new int[k];
int result;
int n = 0;
int i = 0;
while (nresult = 0;
if (isnum(ch[n]))
{
result = ch[n] - '0';
while (nresult = (ch[n] - '0') + 10 * result;
num[i++] = result;
}
++n;
}
for (int j = 0; j cout << num[j] << "\t"; ;
}

bool isnum(char n)
{
return (n >= '0'&&n <= '9');
}

    推荐阅读