解法一:
char str[]="how are you ";
int i=0,j=0;
//其中\0表示字符串结束
while(str[j]!='\0'){
if(str[j]!=' '){
str[i++]=str[j++];
}
else{
str[i++]=str[j++];
while(str[j]==' '){
j++;
}
}
}
str[i]='\0';
cout<<str<<endl;
解法二:正则表达式