注册 登录
编程论坛 C++教室

【求助】解答程序

げ訾澐み 发布于 2007-07-18 13:12, 517 次点击

#include<iostream>
int main()
{
using namespace std;
char ch;
int count=0;
cin.get(ch);
while(cin.fail()==false)
{
cout<<ch;
++count;
cin.get(ch);
}
cout<<endl<<count<<"characters read/n";
return 0;
}
这个程序的循环是怎么进行的
还有他的输出为
the green bird sing in the winter.<enter>
the green bird sing in the winter.
yes,but the crow flies in the dawn.<enter>
yes,but the crow flies in the dawn.
<ctrl><z>
73 characters read
为什么他的字数是73个 不是两句话字数的总和69个吗?
还有不是++count,他自加一次就cout一次吗 ?为什么他就一次输出啊

[此贴子已经被作者于2007-7-18 13:14:16编辑过]

5 回复
#2
げ訾澐み2007-07-18 13:36

哪个大虾帮帮忙啊 ,在线等,谢谢

#3
neverDie2007-07-18 15:32
回车也算一个字符啊,你再仔细数数。
#4
zhaozhiwei2007-07-19 20:17
虽然这个程序我不是太懂。。。
但我试了试修改了一下:
#include<iostream>
using namespace std;
int main()
{

char ch;
int count=0;
cin.get(ch);//以#结束
while(cin.fail()==false)
{
cout<<ch;
++count;
cin.get(ch);
if(ch=='#')
break;
}
cout<<endl<<count<<"characters read\n";
return 0;
}
只有本站会员才能查看附件,请 登录

#5
げ訾澐み2007-07-20 16:50
那后面的CTRL 和Z呢 算不 !!
不算也不够啊
回车是'\N'算一个字符还是两个字符啊

[此贴子已经被作者于2007-7-20 16:53:01编辑过]

#6
野比2007-07-21 00:29
回车是几个? 我都忘了, 汇编里面是两字节的。(CR + LF)...
1