首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2012-03-26 
为什么这个程序做不到那?#includeiostream#includestringusing namespace stdint main(){char strwh

为什么这个程序做不到那?
#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;} 

热点排行