当前位置:网站首页>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
运行结果:
这样就对了
边栏推荐
猜你喜欢
蓝牙技术|上半年全国新增 130 万台充电桩,蓝牙充电桩将成为市场主流
This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean
leetcode:253. 至少需要多少间会议室
物联网应用发展趋势
自监督学习未来是掩码自编码器?KAIST最新《自监督学习掩码自编码器》研究进展
1401 - Web technology 】 【 introduction to graphical Canvas
JCMsuite应用:倾斜平面波传播透过光阑的传输
基于 Next.js实现在线Excel
本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
Redis 复习计划 - Redis主从数据一致性和哨兵机制
随机推荐
如何确定异步 I/O 瓶颈
Qt的QItemDelegate使用
Rust 从入门到精通04-变量
记录都有哪些_js常用方法总结
编程思想_编程有必要给孩子学吗?
Cisco-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)
This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean
基于 Next.js实现在线Excel
蓝牙技术|上半年全国新增 130 万台充电桩,蓝牙充电桩将成为市场主流
一看就会的Chromedriver(谷歌浏览器驱动)安装教程
【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案
[Problem solving] QT update component appears "To continue this operation, at least one valid and enabled repository is required"
AOSP built-in APP franchise rights white list
利用决策树找出最优特征组合
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
16、学习MySQL 正则表达式
word2003按空格键为什么会出现小数点
Go 语言快速入门指南: 变量和常量
ACL 2022 | 社会科学理论驱动的言论建模
Technology sharing | Mini program realizes audio and video calls