| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 693 人关注过本帖
标题:[求助]cin>>问题
只看楼主 加入收藏
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
 问题点数:0 回复次数:3 
[求助]cin>>问题

#include "stdafx.h"
#include <iostream.h>
#include <string>
using namespace std;


int main(int argc, char* argv[])
{
string word;
while ( cin >> word )
cout<<"word read is:"<<word<<"\n";
cout<<"ok:no more words to read:bye!\n";
return 0;
}

输入 the apple is red

预期输出:word read is:the
word read is:apple
word read is:is
word read is:red
ok:no more words to read:bye!

为什么我编译不通过!!!

还有个问题:#include <iostream.h>和#include <iostream>有什么区别吗?

[此贴子已经被作者于2007-10-18 11:33:39编辑过]

搜索更多相关主题的帖子: cin word read apple 
2007-10-18 11:23
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
#include <iostream.h>用这个就不能加using namespace std;std这个名字空间不在iostream.h这个头文件里

最好是用iostream,并加上using namespace std;这是最新的版本用的,加.H的是旧版本,有的编译器已经将它淘汰了

雁无留踪之意,水无取影之心
2007-10-18 13:07
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 
好的,我了解了,谢谢

有个新问题:我如何停下这个程序中的while循环

我准备这样写:(但不知道if的条件)
while ( cin >> word )
{cout<<"word read is:"<<word<<'\n';
if( )
break;}

请指教
2007-10-18 13:49
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
while(cin>>word)
{
if(word=="exit")
break;
cout<<"word read is:"<<word<<endl;
}

雁无留踪之意,水无取影之心
2007-10-18 14:02
快速回复:[求助]cin>>问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014389 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved