instead.
#include
The running result is the same as before.
The member function put can be invoked not only with cout stream objects, but also with other stream objects of the Ostream class.
C + + cin input Flow detailedThe standard input stream is the data that flows from the standard input device (keyboard) to the program. CIN, cout, Cerr, clog 4 stream objects are defined in header file
this. When a keyboard input ends, the input data is stored in the input buffer, and the CIN function directly retrieves data from the input buffer. Because the CIN function retrieves data directly from the buffer zone, sometimes when there is residual data in the buffer zone, the CIN function will directly obtain the residual data without requesting keyboard inp
0. #include
(1) IStream cin; Defining an Input Class object
CIN: Standard input class objects occupy a certain amount of memory space
cin>>a; (Operator overloading)
Function: Used to get content from standard input devices and save to specified memory
Features: can be used to get different data types
can be used for continuous input, but with "space" "/" "enter"
Let's look at the following code:#include #include #include intMain () {intnum =0;STD:: vectorint>Ivec Do{STD::cout"Please input some numbers:"STD:: Endl; while(STD::Cin>> num)//always detects input stream status know how to encounter file Terminator (Ctrl + Z) or wrong inputIvec.push_back (num);if(ivec.size () = =0)STD::cout"error!"STD:: Endl; } while(ivec.size () = =0); System"Pause");return 0;}Now we have some discussion based on this piece of code
When you learn C + +, you must be confused about the functions of the input and output functions, now to summarize the simple use of various functions.CIN has a buffer, the input buffer, that is built. The first input process is this, when the input data is stored in the input buffer at the end of the keyboard input, and the CIN function takes the data directly from the input buffer. Because the CIN functio
differences in scanf and CINAs you know, there are two types of inputs, outputs,-SCANF and CIN in C + +, but there are differences between them, you know. Let's take a look at the assessment below.
Test questions:Enter n number, output n number.
test Environment:
ubuntu12.04 i3cpu 4G memory 7200 RPM HDD
Test Code:(in order to test the correctness of the results, keep the other parts (except the input and output)
scanf's code:
#include
the
When learning C + +, these input functions get a little confused, here to do a summary, in order to review their own, but also hope to be able to help later, if there is a mistake in the place also ask you a lot of advice (this article all programs through the VC 6.0 run) 1. Cin2, Cin.get ()3, Cin.getline ()4, Getline ()5, gets ()6, GetChar () Attached: Cin.ignore (); Cin.get ()//skipping a character, such as the unwanted carriage return, space, and other characters 1,
1. CIN:how the input operation works , the input of the program is built with a buffer, which is the input buffer. The first input process is this, when the input data is stored in the input buffer at the end of the keyboard input, and the CIN function takes the data directly from the input buffer. Because the CIN function takes data directly from the buffer, sometimes when there is residual data in the buf
#include
The above code loop completes the character input
Here is one of the output results:
Enter characters; Enter # to quit:
Ken Run#really Fast
Seekenrun
9 characters Read
Analysis: Why the program output ignored the space.
Explanation: The reason is in CIN. Spaces and line breaks are ignored when CIN reads. Therefore, the spaces in the input are not echoing, and the count is not included.
Ad
Cin (affiliated with istream) is a standard input channel for user input, corresponding to stdin of C. The operating system usually connects it to the keyboard to receive data input from the keyboard. Describes how CIN acquires user data from the keyboard:
Input from the keyboard is first sent"Input buffer"(Streambuf), Accept the variable and then"Input buffer.
"Input bufferUse the following code:
Streambu
Do nine degrees, due to the large amount of data, in many cases, using scanf and printf in place of CIN and cout for input and output, or the error timeout can not AC.
There are three suggestions for increasing the input/output speed of C + +: At the the the the the the the the the the the the the I in main Function,add:std::ios_base::sync_with_stdio (false) which cancel Thesynchronization between
#include
Reference Address: http://www.cnblogs.com/A-Song/archive/2012/01/29/2331204.htmlThe input of the program is built with a buffer, which is the input buffer. The first input process is this, when the input data is stored in the input buffer at the end of the keyboard input, and the CIN function takes the data directly from the input buffer. Because the CIN function takes data directly from the buffer, sometim
C + + input cout and output cin input and output are not formal components of the C + + language. Neither C nor C + + itself provides a specialized statement structure for inputs and outputs. The input output is not defined by the C + + itself, but is defined in the I/O library provided by the compilation system.The output and input of C + + is implemented in the same way as stream. Figure 3.2 and Figure 3.3 represent the process of C + + input and ou
Usage of c++:cin, Cin.getline (), Getline ()Main content:1. CIN Usage2, Cin.getline () usage3, getline () usage3. Issues of attentionFirst, cin>>Usage 1: Enter a number or character#include using namespace Std;Main (){int A, B;cin>>a>>b;cout}Usage 2: Receive a string, the "Space", "tab", "Enter" the end#include using n
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 c
suddenly empty, in view of the Cin object to the value of the mechanism is not very understanding, to explore, and write down, easy to review later. 1#include 2 3 intMainvoid)4 {5 using namespacestd;6 intDate =2;7 Charch;8 while(! (Cin >>date)) {9cout "Not a number.\n";Tencout Endl; OneCin.clear ();//without this, this function will always output "not a number", A //The reas
Principles of standard input: cin and scanf
1. Processing Method of cin
1) if cin reads an integer, it will automatically ignore line breaks and spaces. When the end mark is reached, the number returned by cin> a is false.
Int;
While (cin> ){
Cout
}
Return 0;
Eg: 1, 2
1.cin This method1) Assume that Cin reads an integer. Will ignore line breaks and spaces on its own initiative. A file end tag was encountered. CIN >> A returns the number of falseint A;while (Cin >> a) {cout }return 0;Eg:1, 2, 31 231 A2A 12Note: When CIN reads the ' A ' cha
In many C + + programs, we will have to enter the operation several times. In this case, you will encounter only the first CIN statement being executed, and the subsequent CIN is not executed. This is because the data entered by CIN is placed in the CIN buffer, and after the first use of
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.