当前位置:网站首页>I/O stream summary
I/O stream summary
2022-08-04 14:37:00 【51CTO】
I don't know the exact situation yet,There is a vague understanding,It will be updated continuously in the future
输入流:It's the equivalent of poking a hose into the program,Everything you type is put into the pipe in turn,<<Equivalent to you putting something in a pipe
输出流:This is another hose that pokes into the program,Everything he has calculated is put here,>>Equivalent to you taking something from a water pipe
举个例子
cin>>a>>b;
Equivalent to you putting one in the streama,一个空格,一个b,一个回车;
程序的执行结果是:

One might ask where the whitespace in the stream went?
getchar()The function of the function is to read a string from the keyboard,并带回显,getchar()The function waits for input until exit is pressed,All entered characters before the carriage return are displayed one by one on the screen,但只有第一个字符作为函数的返回值.
读入2The spaces in the middle of the numbers are automatically filtered by the system,Otherwise, the system would not be so stupid
如果你输入1空格2空格回车,spaces will be output,The first space was skipped by the system,The second space will not be skipped by the system
程序的运行结果是:

刚开始输入456,4被getchar()读了,The remaining characters are left in the stream,When the program reads it again, the stream is left behind5给读出来了
scanf和cin结束的'\n'stay in the flow,If encountered, it can be read'\n'的函数,These functions will read in'\n'结束,Nothing else will be entered,能读入'\n'的函数有getchar(),gets(),cin.getline(),
程序的运行结果是:

只输入一个4程序就跑完了,gets()读入的是'\n'
最后总结一下吧,If you just started typing a alphanumeric or something,后面又有一个gets()之类的函数,It should be in the stream'\n'If you eat it, it will be eaten by the next one, which will cause an error,If the following input function will not read in'\n'Then he will'\n'automatically discarded,这个'\n'It doesn't matter if you eat it or not
运行结果:

这样就对了
边栏推荐
- CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
- centos7安装mysql急速版
- [Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution
- LeetCode_模拟_中等_498.对角线遍历
- 【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
- C# 复制列表
- CF1527D MEX Tree(mex&树&容斥)
- vim 常用操作命令
- Redis 复习计划 - Redis主从数据一致性和哨兵机制
- SQL语句的写法:Update、Case、 Select 一起的用法
猜你喜欢

Redis 复习计划 - Redis主从数据一致性和哨兵机制

数据库恢复

Database recovery

广告电商系统开发功能只订单处理

centos7安装mysql急速版

浙江大学团队使用基于知识图谱的新方法,从空间分辨转录组数据中推断细胞间通信状况

MySQL【触发器】

Technology sharing | Description of the electronic fence function in the integrated dispatching system

Qt的QItemDelegate使用

Crawler - basic use of selenium, no interface browser, other uses of selenium, cookies of selenium, crawler cases
随机推荐
广告电商系统开发功能只订单处理
ASA归因:如何评估关键词的投放价值
杭电校赛(逆袭指数)
X射线掠入射聚焦反射镜
C# 复制列表
G.登山小分队(暴力&dfs)
vim 常用操作命令
Makefile syntax and usage notes
记录都有哪些_js常用方法总结
js深拷贝和浅拷贝具体使用区别_es6深拷贝和浅拷贝
Makefile 语法及使用笔记
License server system does not support this version of this feature
【 HMS core 】 【 Media 】 online video editing service 】 【 material can't show, or network anomalies have been Loading state
xampp安装包含的组件有(php,perl,apche,mysql)
G. Mountaineering Squad (violence & dfs)
CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
在腾讯,我的试用期总结!
如何和程序员谈恋爱
JCMsuite应用:倾斜平面波传播透过光阑的传输
【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案