当前位置:网站首页>About CIN, scanf and getline, getchar, CIN Mixed use of getline
About CIN, scanf and getline, getchar, CIN Mixed use of getline
2022-04-23 08:55:00 【laobuzhang】
When they are mixed, sometimes it is impossible to enter a string or there are more spaces in the string
Here's why :
cin and scanf Or leave a space after the input buffer is completed \n( See what you end with when you type )
And the next one cin and scanf Will directly ignore the remaining space or \n, Read in your new input
however getline,getchar,cin.getline It doesn't ignore this space or \n, They'll read this into
If cin perhaps scanf What's left is a space , Then use getline,getchar,cin.getline The input string will be preceded by one more space
If cin perhaps scanf What's left is \n, Then use getline,getchar,cin.getline Will read the \n And think you entered \n So as to directly end the input
resolvent :
After use cin and scanf after , add a sentence getchar() Eat the remaining spaces or \n, And then use getline,getchar,cin.getline
Be careful :
1.cout and printf It doesn't affect
2.getline,getchar,cin.getline There will be no spaces or \n
版权声明
本文为[laobuzhang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230811426998.html
边栏推荐
- 求简单类型的矩阵和
- L2-024 部落 (25 分)(并查集)
- Failed to prepare device for development
- Latex paper typesetting operation
- Cadence process angle simulation, Monte Carlo simulation, PSRR
- GUI编程简介 swing
- How much inventory recording does the intelligent system of external call system of okcc call center need?
- Chris LATTNER, father of llvm: the golden age of compilers
- Strength comparison vulnerability of PHP based on hash algorithm
- MATLAB入门资料
猜你喜欢
Test your machine learning pipeline
Introduction to GUI programming swing
经典题目刷一刷
Notes on xctf questions
Cadence process angle simulation, Monte Carlo simulation, PSRR
The K neighbors of each sample are obtained by packet switching
K210 learning notes (II) serial communication between k210 and stm32
LaTeX论文排版操作
Idea package jar file
Use of Arthas in JVM tools
随机推荐
idea打包 jar文件
Play with binary tree (25 points)
微信:获取单个标签所有人
mycat配置
RCC introduction of Hal Library
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution
dataBinding中使用include
【IndexOf】【lastIndexOf】【split】【substring】用法详解
Bk3633 specification
L2-024 tribe (25 points) (and check the collection)
valgrind和kcachegrind使用运行分析
Enterprise wechat application authorization / silent login
Reference passing 1
政务中台研究目的建设目标,建设意义,技术创新点,技术效果
Failed to prepare device for development
Latex mathematical formula
玩转二叉树 (25 分)
Go language self-study series | golang structure as function parameter
Swagger document export custom V2 / API docs interception