关于cin

#include<iostream>
using namespace std;
const int DECLARED_SIZE=10;

int main()
{
 cout<<"Enter up to ten letters followed by a period"<<endl;
 char letter_box[DECLARED_SIZE],next;
 int index=0;
 cin>>next;
 while((next!='.')&&(index<DECLARED_SIZE))
 {
  letter_box[index]=next;
  index++;
  cin>>next; //读入字符不必用空白符间隔开
 }
 int number_used=index;
 cout<<"Here they are backwards:"<<endl;
 for(index=number_used-1;index>=0;index--)
  cout<<letter_box[index];
 cout<<endl;

 return 0;

可以这样输入 abc.

也可以这样输入 a b c .

还可以这样输入

a

b

c

.

对于输入字符来说,cin读取输入时结果都是一样的

 

#include<iostream>
using namespace std;
const int DECLARED_SIZE=10;

int main()
{
 cout<<"Enter up to ten number followed by a period"<<endl;
 int int_array[DECLARED_SIZE],next;
 int index=0;
 cin>>next;
 while((next>=0)&&(index<DECLARED_SIZE))
 {
  int_array[index]=next;
  index++;
  cin>>next;//读入数字要用空白符间隔开
 }
 int number_used=index;
 cout<<"Here they are backwards:"<<endl;
 for(index=number_used-1;index>=0;index--)
  cout<<int_array[index];
 cout<<endl;

 return 0;
}

只能后两种输入方法 1 2 3 -1

1

2

3

-1

用cin读取输入的数字,必须用空白符间隔开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值