您的位置:首页 > 编程语言 > C语言/C++

C++去掉字符串中重复空格

2016-08-12 14:53 447 查看
#include<iostream>

#include<string.h>

using namespace std;

void delSpace(char* buf)

{
//int len = strlen(buf);
//int i,j;
//if(i = 0; i < len;i++)
char* fast = buf;
char* temp = buf;
while(*fast!='\0')
{
if(*fast!=' ')
{
*temp=*fast;
temp++;
fast++;
}
else
{
while(*fast == ' ')
fast++;
//cout<<*fast;
*temp=' ';
temp++;
}
}
*temp='\0';

}
int main()

{

char s[100];
int i = 0;
cin.getline(s,100);
delSpace(s);
i=0;
while(1)
{
if(s[i]=='\0')
break;
else
cout<<s[i];
i++;
}
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 C++