C++实现一个字符串中的数字以外的字符拷贝另一个字符串中。

C++实现一个字符串中的数字以外的字符拷贝另一个字符串中。

问题描述:

a:-bc@dC+

代码如下,如有帮助,请帮忙采纳一下,谢谢。

img

代码

#include <iostream>

using namespace std;
int main()
{
    int i=0,j=0;
    char buf1[100],buf2[100];
    cin.getline(buf1,99); //读取一行
    while (buf1[i])
    {
        if(buf1[i] <'0' || buf1[i]>'9')
            buf2[j++] = buf1[i];
        i++;
    }
    buf2[j] = '\0';
    cout << buf2<<endl;
    return 0;
}