以下是引用边城路人在2007-4-20 12:43:03的发言:
#include <iostream.h>
void main()
{
char s[50];
int i;
cout<<"Input a string:";
cin.get(s,50);
cout<<"The string you put in:"<<s<<endl;
cout<<"Output string:";
for(i=0;i<50;i++)
{
if(s[i]!=' '&&s[i]=='\0')
cout<<s[i];
else if(s[i]==' ')
continue;
else
break;
}
}
运行结果:
Input a string:what are you doing?
The string you put in:what are you doing?
Output string:Press any key to continue
#include <iostream.h>
void main()
{
char s[50];
int i;
cout<<"Input a string:";
cin.get(s,50);
cout<<"The string you put in:"<<s<<endl;
cout<<"Output string:";
for(i=0;i<50;i++)
{
if(s[i]!=' '&&s[i]=='\0')
cout<<s[i];
else if(s[i]==' ')
continue;
else
break;
}
}
运行结果:
Input a string:what are you doing?
The string you put in:what are you doing?
Output string:Press any key to continue
这个没有输出结果