为什么这个程序做不到那?该如何处理

为什么这个程序做不到那?
#include<iostream>
#include<string>


using namespace std;
int main()

{
  char str;
while(cin>>str)
cout<<str;
}

怎么能做到 输入 ab cd 输出ab cd?

------解决方案--------------------
C/C++ code
#include <iostream> 
#include <string> 
#include<sstream>

using   namespace   std; 
int   main() 

{ 
    string   str;    
    getline(cin,str);
    cout<<str; 
}

------解决方案--------------------
C/C++ code

#include<iostream>

using namespace std;

int main()
{
    char str;
    cin>>noskipws;
    while( cin>>str )
        cout<<str;
    return 0;
}

------解决方案--------------------
读行或检测空格判断,单读char只是一个字符,完毕
------解决方案--------------------
#include <iostream> 
#include <string> 


using namespace std; 
int main() 


// char str; 
string str;
while(cin> > str) 
cout < <str; 


//怎么能做到 输入 ab cd 输出ab cd?
这样就行
------解决方案--------------------
C/C++ code

#include <iostream> 
#include <string> 
#include<sstream>

using   namespace   std; 
int   main() 

{ 
    string   str;    
    while(getline(cin,str))
{
cout<<str; 
}
    
system("pause");
return 0;
}

------解决方案--------------------
C/C++ code

#include <iostream > 
#include <string > 
using namespace std; 

int main() 
{ 
  
   string   str;    
   while(getline(cin,str))
   {
      cout<<str<<endl; 
   }
  
   system("pause");
   return 0;
}