当前位置:网站首页>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)
- Single chip microcomputer nixie tube stopwatch
- STM32 uses Hal library. The overall structure and function principle are introduced
- RCC introduction of Hal Library
- Flink reads MySQL and PgSQL at the same time, and the program will get stuck without logs
- dataBinding中使用include
- 企业微信应用授权/静默登录
- xctf刷题小记
- PLC的点表(寄存器地址和点表定义)破解探测方案--方便工业互联网数据采集
- L2-3 浪漫侧影 (25 分)
猜你喜欢

MATLAB 画五星红旗

Solidity 问题汇总

valgrind和kcachegrind使用運行分析

Please arrange star trek in advance to break through the new playing method of chain tour, and the market heat continues to rise

Introduction to matlab

Non duplicate data values of two MySQL query tables

Resource packaging dependency tree

php基于哈希算法出现的强弱比较漏洞

L2-3 romantic silhouette (25 points)

Star Trek's strong attack opens the dream linkage between metacosmic virtual reality
随机推荐
Restore binary tree (25 points)
Correct method of calculating inference time of neural network
Get the absolute path of the class according to the bytecode
Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
idea打包 jar文件
DJ music management software pioneer DJ rekordbox
Go语言自学系列 | golang嵌套结构体
Cadence process angle simulation, Monte Carlo simulation, PSRR
数字政府建设中政务中台中的技术创新点
Redis Desktop Manager for Mac(Redis可视化工具)
Flink reads MySQL and PgSQL at the same time, and the program will get stuck without logs
关于堆的判断 (25 分) 两种插入方式
Arbre de dépendance de l'emballage des ressources
The K neighbors of each sample are obtained by packet switching
【IndexOf】【lastIndexOf】【split】【substring】用法详解
Valgrind et kcachegrind utilisent l'analyse d'exécution
Output first order traversal according to second order and middle order traversal (25 points)
Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
OneFlow学习笔记:从Functor到OpExprInterpreter
The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution