当前位置:网站首页>(1) Input and output
(1) Input and output
2022-07-16 07:59:00 【Steal the mask and run away】
( One ) Input and output
List of articles
1、 Read
#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;
}
result :
2、 Output
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// left right fixed scientific setprecision setfill It has aftereffect
// setw(10) No aftereffect
// fixed and setprecision The role of . As long as you set up , Will always be ( Unless you put fixed eliminate ,setprecision() modify )
//%md m Bit right aligned output , High fill space
//%0md m Bit right aligned output , High compensation 0
double n;
cin>>n;
cout<<n<<endl; // Default to 6 precision , So the output is 12.3457
// Think of it this way , Omitted by default setprecision(6) This code
cout << setprecision(4) << n << endl; // Change to 4 precision , So the output is 12.35
cout << "-------" << endl;
cout << fixed << setprecision(4) << n << endl;
// added fixed It means fixed point display , So here precision refers to decimal places , Output is 12.3457
cout << n << endl;
// fixed and setprecision The role of , Still show 12.3457
cout.unsetf( ios::fixed );
// Removed fixed, So the accuracy is restored to the significant digits of the whole value , Is shown as 12.35 setprecision(4) The role of still exists
cout << n << endl;
// Return to the original , Output is 12.3457
cout << "-------" << endl;
cout << setprecision(6) << n << endl;
cout << scientific << n << endl; // scientific And fixed similar One is scientific counting , One is in decimal form
cout.unsetf( ios::scientific);
cout << n << endl;
cout << "-------" << endl;
// setfill It must be written at the beginning
cout << setfill('*')<< right << setw(10) << n << endl;
cout << setfill('#')<< setw(10) << n << endl;
// setw(10) No aftereffect So it needs to be in every n with
cout << setfill('*')<< left << n << endl;
cout << setfill('#')<< setw(10) << n << endl;
cout<<"-------"<<endl;
int m;
cin>>m;
printf("%6d\n",m); //%md m Bit right aligned output , High fill space
printf("%06d\n",m);//%0md m Bit right aligned output , High compensation 0
return 0;
}
Output results

边栏推荐
- Dynamic programming + combinatorial mathematics
- Use redis' sorted set to make weekly hot reviews
- 递归实现组合型模型
- Concurrent simulation of program ape's exclusive "pressure test tool"
- ABAP BAPI 复制标准项目模板实现项目立项
- Principle and configuration of static routing
- Redis只能做缓存?太out了!
- C#笔记-C#7.0 Essential
- Re regular expression
- c#使用MQTT通信
猜你喜欢
随机推荐
.net 5使用LogDashboard
c语言编译器介绍
Heap and heap sort
CCF 201909-1 称检测点查询
一次简单的 JVM 调优,拿去写到简历里
C#驗證碼
Day 12 of leetcode + day 1 of DL
C excel net core reading xlsm
Day 14 of leetcode
Dynamic programming + combinatorial mathematics
C#笔记-C#7.0 Essential
全排列next_permutation()函数
.NET Core使用Basic基本认证中间件
Attack and defense World Web
Master-slave copy reading and writing separation nanny level teaching
递归实现指数型枚举
Day 8 of leetcode question brushing
jsonp原理
Azkaban overview
递归实现组合型模型







