65,204
社区成员
 发帖
 发帖 与我相关
 与我相关 我的任务
 我的任务 分享
 分享#include<iostream>
using namespace std; 
int main()
{	char ch=0;
	int n=0,m=0,j=0;
	cout<<"请输入任意字符:"<<endl;
	do{cin>>ch;
		if(ch!='#')
		{j++;
			if(ch=='\0')
				++m;
			else
				++n;}
		else
			break;
	}while(true);
	cout<<"#号前的空格有"<<m<<"个"<<endl;
	cout<<"#号前的非空格字符有"<<n<<"个"<<endl;
	cout<<"#号前的字符有"<<j<<"个"<<endl;
	return 0;
}
必须清空缓冲区再取数据:fflush(stdin);
#include <iostream> 
using namespace std; 
int main()
{    char ch=0;
    int n=0,m=0,j=0;
    cout<<"请输入任意字符:"<<endl;
    do{
		//cin>>ch;
		cin.get(ch);
        if(ch!='#')
        {
			j++;
            if(ch==' ')
                ++m;
            else
                ++n;
		}
        else
		{
            break;
		}
		fflush(stdin);
    }while(true);
    cout<<"#号前的空格有"<<m<<"个"<<endl;
    cout<<"#号前的非空格字符有"<<n<<"个"<<endl;
    cout<<"#号前的字符有"<<j<<"个"<<endl;
    return 0;
}
#include<iostream>
using namespace std; 
int main()
{    char ch=0;
    int n=0,m=0,j=0;
    cout<<"请输入任意字符(以#号结束):"<<endl;
    do{
        cin.get(ch);
        if(ch!='#')
        {
            j++;
            if(ch==' ')
                ++m;
            else
                ++n;}
        else
            break;
    }while(true);
    cout<<"#号前的空格有"<<m<<"个"<<endl;
    cout<<"#号前的非空格字符有"<<n<<"个"<<endl;
    cout<<"#号前的字符有"<<j<<"个"<<endl;
    system("pause");
    return 0;
}
#include<iostream> 
using namespace std; 
int main() 
{ 
	char ch=0; 
	int n=0,m=0,j=0; 
	cout<<"请输入任意字符:"<<endl; 
	do
	{
		ch=getchar(); 
		if(ch!='#')
			{
				j++; 
				if(ch==' ')
					++m; 
				else  
					++n;
		} 
		else 
			break; 
	}while(true); 
	cout<<"#号前的空格有"<<m<<"个"<<endl; 
	cout<<"#号前的非空格字符有"<<n<<"个"<<endl; 
	cout<<"#号前的字符有"<<j<<"个"<<endl; 
	return 0; 
}
#include<iostream>
using namespace std; 
int main()
{    char ch=0;
    int n=0,m=0,j=0;
    cout<<"请输入任意字符:"<<endl;
    do{cin.get(ch);
        if(ch!='#')
        {j++;
            if(ch==' ')
                ++m;
            else
                ++n;}
        else
            break;
    }while(true);
    cout#号前的空格有"<<m<<"个"<<endl;
    cout<<"#号前的非空格字符有"<<n<<"个"<<endl;
    cout<<"#号前的字符有"<<j<<"个"<<endl;
    return 0;
}