将一句话所有的单词换行:
1.#include "iostream.h"
#include "stdio.h"
void main()
{char ch;
while((ch=getchar())!='.')
if(ch==' ')
cout<<endl;
else
cout<<ch;}
2..#include "iostream.h"
#include "stdio.h"
void main()
{char ch;
while(cin>>ch,ch!='.')
if(ch==' ')
cout<<endl;
else
cout<<ch;}
问什么2反而把单词全连起来了?
由此想问cin和getchar得区别.
多谢!
1.#include "iostream.h"
#include "stdio.h"
void main()
{char ch;
while((ch=getchar())!='.')
if(ch==' ')
cout<<endl;
else
cout<<ch;}
2..#include "iostream.h"
#include "stdio.h"
void main()
{char ch;
while(cin>>ch,ch!='.')
if(ch==' ')
cout<<endl;
else
cout<<ch;}
问什么2反而把单词全连起来了?
由此想问cin和getchar得区别.
多谢!