In the previous section, we mentioned in several examples that the CIN function has an error, so that no read operation is performed (Program 8 ). We often see functions such as cin. Clear (), Cin. Ignore (), Cin. Fail () in the program. These functions are related to the troubleshooting of
Differentiation of cin, cin. get (), cin. getline (), cin. getcin. getline
1 cin is mainly used to input numbers
# Include Using namespace std;Main (){Int a, B;Cin> a> B;Cout
Input: 1 Press enter 2 press ENTEROutput: 3
2 when
Scanf, gets, getchar, cin, cin. get, cin. getline, getline summary, cin. getcin. getline
I. scanf
Scanf can be used to read numbers, characters, and strings;
Conclusion:(1) When scanf reads a single character (% c) from the buffer, if the first character in the buffer is a space, tab, or line feed separator, scanfNoIgn
When I was learning C ++, these input functions were a bit confusing. Here I will make a summary. I hope it will be helpful for later users to review them, if there are any errors, please kindly advise (all in this articleProgramAll run through VC 6.0) reprinted, please keep the author information;1. Cin1. Cin. Get ()2. Cin. Getline ()3. Getline ()4. Gets ()5. getchar ()
1.
Usage of functions such as Cin, Cin. Get (), Cin. Getline (), Getline (), and gets ()
When I was learning C ++, these input functions were a bit confusing. Here I will make a summary. I hope it will be helpful for later users to review them, if there are any errors, please kindly advise (all in this articleProgramAll run through VC 6.0) reprinted, please keep th
1. Cin, Cin. Get, Cin. Getline
When CIN reads data, it ends with a space. When the space character is discarded, the input carriage return is complete, which is normal.
Cin. Get is used to read characters. The input carriage return ends, but the carriage return and space cha
1,CIN
Usage 1: the most basic and common usage. Enter a number:
# Include
Using namespace STD;
Main ()
{
Int A, B;
Cin> A> B;
Cout
}
Input: 2 [Press enter] 3 [Press enter]
Output: 5
Usage 2: accept a string. When "space", "tab", and "Press ENTER" are all completed
# Include
Using namespace STD;
Main ()
{
Char A [20];
Cin>;
Cout
}
Input: jkljkljkl
Output: jklj
When I was learning C ++, these input functions were a bit confusing. Here I will make a summary. I hope it will be helpful for later users to review them, if there are any errors, please give me more advice (all the programs in this article are run through VC 6.0)
1. Cin2. Cin. Get ()3. Cin. Getline ()4. Getline ()5. Gets ()6. getchar ()
Appendix: cin. Ignore ()
A few C ++ input functions are always unclear. Let's sum up!
1. Cin
1. Cin. Get ()
2. Cin. Getline ()
3. Getline ()
4. Gets ()
5. getchar ()
1. Cin>
Usage 1: the most basic and common usage. Enter a number:
# Include
Using namespace STD;
Main ()
{
Int A, B;
Array:
Float loans [20];
The loans type is not "array" but "float array ". This emphasizes that the loans array is created using the float type.
String:
Char dog [5] = {'A', 'B', 'C', 'D', 'E'}; // not a string (not a string)
Char dog [5] = {'A', 'B', 'C', 'D', '\ 0'}; // a string (a string)
Differences between character and string
Char shirt_size = 's'; In the ASCII system, 's' is only another method of 83.
However, "S" represents a string consisting of two characters (S and \ 0. And "S" actu
The end of CIN
If you use CIN>... If you have input before using cin. Getline, you need to process it. There are many processing methods. You can go to CIN>... Add the statements cin. Get ();.
Use Getline () to read the input li
Many beginners think that the CIN function is a very simple function! The CIN function has a lot of knowledge to know (for example, what is the return value of CIN, And what member functions are provided by CIN, such as cin. clear (), Ci
Gain a deep understanding of the mechanism of CIN error handling, and gain a deep understanding of functions such as cin. Clear/cin. Ignore/cin. Good/cin. Fail.
In the previous section, we mentioned in several examples that the CIN
About using CIN
Cin. Get () getchar (), the terminator of Getline Input
Input values of CIN. Get (), getchar, Cin. Getline
1. How to handle the first character encountered by these functions
Cin. Get ()
# Include
# Include
Using namespace STD;
Int main ()
{
Char;
Char B
Detailed description of the cin standard input stream and the cin input stream
A standard input stream is used to input data to a program from an input device (such as a keyboard. in the header file iostream. the cin, cout, and cerr objects are defined in h. cin is the input stream, and others are the output stream.
In
-----------------------
1. Cin. Get ()
(1). Cin. Get () extract a single character. You can extract carriage return and space.
A = cin. Get ();
(2) Same as (1)
Cin. Get ();
(3 ).
Cin. Get (character array, number of characters N, Terminator character); // Terminator chara
Char C (0 );
Cin> C. When a character is entered, all white spaces in the input will be missed, and the character "C ++" is also a blank character, so it will also be missed;
Cin. Get (); it always reads the next character and does not omit any;
CodeAs follows:
# Include
see a lot of C + + code written in Cin.get () after the comment said this is the absorption carriage return, do not know what it means!
See a lot of C + + code written in Cin.get () after the comment said this is the absorption carriage return, do not know what it means!
For example
cout
Characters have always
been difficult to manipulate because you enter the data is a carriage return as the end, but the carriage return is not entered into the program, if the following appear to enter the
Which of the following is a quick question about scanf and cin? scanf and cin
Start with c ++ and run cin and cout all day long.
Cout times out until one day when cin is used.
Scanf is much faster than cin.
However, I later heard that the
1. After we login space can, click the Launch button behind the web host
2. Then enter and then click the Mangel button, as shown in the following figure
3. Into the Mangel interface we find the following database, is the data base here is a detail is not to click phpMyAdmin, because this and domestic a little different, can not create a database can only query data operations, we click on the back of MySQL Database Open
4. Then fill in the Create New database, click on can be created, bu
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.