当前位置:网站首页>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
运行结果:

这样就对了
边栏推荐
猜你喜欢
![[The Art of Hardware Architecture] Study Notes (1) The World of Metastability](/img/ac/54e4e13d9df90e96933c69623b770e.png)
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability

利用决策树找出最优特征组合

技术分享| 融合调度系统中的电子围栏功能说明

Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market

Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source

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

谷歌插件.crx文件下载后被自动删除的解决方法

Cisco - Small Network Topology (DNS, DHCP, Web Server, Wireless Router)

CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source

【剑指offer59】队列的最大值
随机推荐
广告电商系统开发功能只订单处理
本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
xpath获取带命名空间节点注意事项
Google plug-in. Download contents file is automatically deleted after solution
LeetCode_模拟_中等_498.对角线遍历
如何和程序员谈恋爱
OAID是什么
Redis 复习计划 - Redis主从数据一致性和哨兵机制
[Opportunity Enlightenment-60]: "Soldiers, Stupid Ways"-1- Opening: "Death" and "Life" are the way of heaven
RS|哨兵二号(.SAFE格式)转tif格式
Makefile syntax and usage notes
word2003按空格键为什么会出现小数点
Rust from entry to proficient 04-variables
leetcode:255 验证前序遍历序列二叉搜索树
How to install postgresql and configure remote access in ubuntu environment
leetcode:212. 单词搜索 II
理论篇1:深度学习之----LetNet模型详解
基于 Next.js实现在线Excel
C# winforms 输入颜色转换颜色名
Set partition minimum difference problem (01 knapsack)