当前位置:网站首页>(一)输入输出
(一)输入输出
2022-07-13 18:06:00 【偷完面具就瞎跑】
(一)输入输出
1、读取
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int a;
int i[10];
memset(i,0,sizeof(i));
while(scanf("%d",&a) != EOF){
i[0]++;
}
cout<<"(1) "<<i[0]<<endl;
while(cin>>a){
i[1]++;
}
cout<<"(2) "<<i[1]<<endl;
while(scanf("%d",&a)!=-1){
i[3]++;
}
cout<<"(3) "<<i[3]<<endl;
return 0;
}
结果:
2、输出
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// left right fixed scientific setprecision setfill 具有后效性
// setw(10) 不具有后效性
// fixed和setprecision的作用还在。只要你设置了,会一直在(除非你把fixed清除,setprecision()修改)
//%md m位右对齐输出,高位补空格
//%0md m位右对齐输出,高位补0
double n;
cin>>n;
cout<<n<<endl; // 默认以6精度,所以输出为 12.3457
// 可以这样认为,默认省去了setprecision(6)这句代码
cout << setprecision(4) << n << endl; // 改成4精度,所以输出为12.35
cout << "-------" << endl;
cout << fixed << setprecision(4) << n << endl;
// 加了fixed意味着是固定点方式显示,所以这里精度指的是小数位,输出为12.3457
cout << n << endl;
// fixed和setprecision的作用还在,依然显示12.3457
cout.unsetf( ios::fixed );
// 去掉了fixed,所以精度恢复成整个数值的有效位数,显示为12.35 setprecision(4)的作用仍存在
cout << n << endl;
// 恢复成原来的样子,输出为12.3457
cout << "-------" << endl;
cout << setprecision(6) << n << endl;
cout << scientific << n << endl; // scientific与 fixed 类似 一个是科学计数,一个是小数形式
cout.unsetf( ios::scientific);
cout << n << endl;
cout << "-------" << endl;
// setfill必须写在开头
cout << setfill('*')<< right << setw(10) << n << endl;
cout << setfill('#')<< setw(10) << n << endl;
// setw(10) 不具有后效性 所以需要在每个n前加上
cout << setfill('*')<< left << n << endl;
cout << setfill('#')<< setw(10) << n << endl;
cout<<"-------"<<endl;
int m;
cin>>m;
printf("%6d\n",m); //%md m位右对齐输出,高位补空格
printf("%06d\n",m);//%0md m位右对齐输出,高位补0
return 0;
}
输出结果

边栏推荐
- How to self-study software testing? [super comprehensive analysis from 0 to 1] (with learning notes)
- The experience of finding a job after coming out of the software testing training class taught me these five things
- Semaphore, countdownlatch use and talking about the source code
- 守望相助
- 为什么不能用Redis过期监听实现关闭订单?
- appium中desired_caps参数记录
- MySQL foundation related (important)
- 丑数
- Attack and defense World Web
- Basic introduction to flask 6 - Context
猜你喜欢

Data storage and disaster recovery (2nd Edition) editor in chief Lu Xianzhi Wu Chunling comprehensive training answer

文件管理-阿里云OSS学习(一)

Looking at "money" ~ the experience of a tester with two years' graduation and an annual salary of 30W

Automatically back up mysql. And keep the case for 7 days

一位年薪35W的测试被开除,回怼的一番话,令人沉思

3、 Experimental report on the implementation of SMB sharing and FTP construction by freenas

VLAN和Trunnk

【LeetCode】1252. Number of odd value cells

2021/12/12 attack and defense world reverse question record

守望相助
随机推荐
Five years' experience: the monthly salary is 3000 to 30000, and the change of Test Engineers
[MySQL] paging query step pit
太香了, 终于明白为什么这么多人要转行软件测试了~
【LeetCode】1252. Number of odd value cells
字节测试总监熬夜10天肝出来的测试岗面试秘籍,给你的大厂梦插上翅膀~
2-3树 B树 b+树
The workplace crisis of the tester is 35 years old? No, but the middle-aged was laid off!
30岁转行软件测试靠谱吗?一个过来人的心路历程送给迷茫的你
Basic principle and configuration of switch
How to self-study software testing? [super comprehensive analysis from 0 to 1] (with learning notes)
TCP协议详解
自动备份MySQL。且保留7天案例
2个用例之间存在关联,怎么解?
The experience of finding a job after coming out of the software testing training class taught me these five things
Redis只能做缓存?太out了!
Commodity module development
将一个数分解成多个加数相加的形式
Attack and defense World Web
Why is it said that the testing post is a giant pit? The 10-year-old tester told you not to be fooled~
RAID磁盘阵列