第13周项目5(2)去除字符串空格

来源:互联网 发布:linux怎么退出vi 编辑:程序博客网 时间:2024/05/01 19:57
/*。*Copyright(c)2014,烟台大学计算机学院*All right reserved,*文件名:test.cpp*作者:biyutang*完成日期:2014年11月23日*版本号:v1.0*问题描述:*输入描述:输入x*程序输出:输出Y*/#include<iostream>using namespace std;int main(){    char str[50]="I am a happy boy\'s daddy.";    int i=0,j=0;    while(str[i]!='\0')    {        if(str[i]!=' ')            str[j++]=str[i++];        else            i++;    }    str[j]='\0';    cout<<"整理后的字符串:"<<str<<endl;    return 0;}

运行结果:


0 0