- #include<iostream>
- using namespace std;
- int main()
- {
- char ch[100001]={0};
- char c;
- int i=0;
- int count=0;
- cout<<"请输字符串:(长度不大于十万)";
- while((c=cin.get())!='\\n')
- {
- if(c == ' ')
- {
- count++;
- continue;
- }
- i++;
- ch[i] = c;
- }
- cout<<"空格数:"<<count<<endl;
- cout<<"去除空格后的字符为:";
- for(int j = 1;j<=i;j++)
- cout<<ch[j];
- cout<<endl;
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/140320149041.html
来源: http://www.codesnippet.cn/detail/140320149041.html