当前位置:网站首页>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
边栏推荐
猜你喜欢

Study notes of deep learning (8)

Non duplicate data values of two MySQL query tables

深度学习框架中的自动微分及高阶导数

L2-3 浪漫侧影 (25 分)

2021 Li Hongyi's adaptive learning rate of machine learning

使用flask和h5搭建网站/应用的简要步骤

Arbre de dépendance de l'emballage des ressources

Solidity 问题汇总

L2-3 romantic silhouette (25 points)

LaTeX论文排版操作
随机推荐
Summary of solid problems
Introduction to matlab
Whether the same binary search tree (25 points)
Download and install bashdb
Is Zhongyan futures safe and reliable?
MYCAT configuration
Concave hull acquisition method based on convex hull of point cloud
使用flask和h5搭建网站/应用的简要步骤
Find the sum of simple types of matrices
Use of Arthas in JVM tools
Go language self-study series | initialization of golang structure
Study notes of deep learning (8)
DJ music management software pioneer DJ rekordbox
调包求得每个样本的k个邻居
Solidity 问题汇总
dataBinding中使用include
Share the office and improve the settled experience
Failed to prepare device for development
After a circle, I sorted out this set of interview questions..
资源打包关系依赖树