首页 > 其他 > 详细

第六章 复习题

时间:2014-12-07 21:33:46      阅读:236      评论:0      收藏:0      [点我收藏+]
 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     char ch;
 6     int ct1,ct2;
 7     ct1=ct2=0;
 8     while((ch=cin.get())!=$)
 9     {
10         cout<<ch;
11         ct1++;
12         if(ch=$)ct2++;
13         cout<<ch;
14     }
15     cout<<"ct1="<<ct1<<",ct2="<<ct2<<endl;
16     return 0;
17 }

输入

hi!

send $10 or $20 now!

输出结果是

hi!

h$i$!$

$send $10 or $20 now!

$$s$e$n$d$ $ct1=9,ct2=9

因为第12行是ch=‘$‘而不是ch==‘$‘。是赋值而不是判断。

第六章 复习题

原文:http://www.cnblogs.com/taoxiuxia/p/4149843.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!