What is the usage of cin, cin.get (), cin.getline (), getline (), gets (), etc.
What this article shares with you is about the usage of cin, cin.get (), cin.getline (), getline (), gets () and other functions. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
When learning C++, these input functions are a little confused; here is a summary, for my own review, I hope it will be helpful to the newcomers, and if there are any mistakes, I would like to ask you for advice (all the programs in this article are run through VC 6.0)
1 、 cin
2. Cin.get ()
3. Cin.getline ()
4. Getline ()
5. Gets ()
6. Getchar () attached: cin.ignore (); cin.get () / / skip a character, such as unwanted carriage return, space and other characters 1, cin > > usage 1: the most basic and most commonly used usage, enter a number: # include
Using namespace std
Main ()
{
Int a,b
Cin > > a > > b
Coutnoskipws > > input [j]; / / if you don't want to skip white space characters, use noskipws flow control usage 2: accept a string and end # include with "space", "TAB" and "enter"
Using namespace std
Main ()
{
Char a [20]
Cin > > a
Cout