Disclaimer: This article turns from a few 1234 blogs
In the contest, when the large data is encountered, the reading file becomes the bottleneck of the running speed of the program, and it needs a faster reading mode. It is believed that almost all C + + learners have stumbled over the slow speed of the CIN machine, and have vowed not to read the data on the CIN. Others say that the speed of Pascal's read s
Consider the following code:
# Include Using namespace std;
Int main (){Int;While (cout Cout Return 0;}
The intention is to allow the user to select a number ranging from 1 to 10. If it is not a number ranging from 1 to 10, re-enter it.
Analysis:
If the user inputs an int not greater than 1-10, the program runs correctly and prompts the user to re-enter it.
However, if the user mistakenly inputs a character char, the result is that the while loop is always executed!
Error analysis:
When
Jery's earliest intention was to support a pure test of an iostream class object, like this:
If (CIN )...
To enable CIN to obtain a real value, Jerry first defines a conversion operator for it, namely, operator int (). In the case of good behaviors such as above, it can indeed run correctly. But in the following error program design, its behavior will be puzzling:
Ci
1.cin
C + + uses CIN to easily read the characters entered by the keyboard, for example:
Test input
#include
First, we enter only one word for each input, as follows:
But if we fill in more than two words in the first input:
It can be found that the second input has not yet had time to respond, it has been shown.
The reason is that CIN uses whitespace (space
C + + Basics: Summary of various input methods, CIN, Cin.get (), Cin.getline (), Getline (), gets (), GetChar ()
Input principle Brief:
The input buffer of the program is built with a buffer. Each time the input process is the same, the input data is deposited into the input buffer when the keyboard input is finished
1.cin
Read Data according to the variable type of STH in
How to accelerate the input and output of c ++ In the ACM competition? How can we make the cin speed equal to the scanf speed? What is the fastest input/output method ?, Cinscanf
During the competition, when encountering big data, reading files often becomes the bottleneck of program running speed and requires faster reading. I believe that almost all C ++ learners are stuck at the slow speed of the cin ma
Reading today when you see the code while (Cin>>val), suddenly thinking about how to write the legality of how to determine. We all know that CIN is a stream object, and the >> operator returns the stream object on the left, that is, Cin>>val returns CIN, so while (Cin>>val)
Differences in scanf and CINCited example: http://www.cnblogs.com/shenben/p/5516996.htmlAs you know, there are two types of inputs and outputs in C + +,-scanf and CIN, but there are differences between them, you know? Let's see the assessment below!Test questions:Enter n number, output n number.test Environment:ubuntu12.04 i3cpu 4G memory 7200 RPM HDDTest Results:Test results using the time test of Linux, the results are as follows: When 10000 sets of
Today, I saw a post on csdn, which reminds me of the while (CIN> S) exit problem.
ProgramAs follows:
# Include # Include String ># Include # Include # Include Using Namespace STD; Int Main (){Vector String > STR; String S; While (CIN> S)Str. push_back (s ); For (Vector String >:: Iterator it = Str. Begin (); it! = Str. End (); ++ it)Cout " " Sort (Str. Begin (), str. End ()); For (Vector String
1, cin>>Usage 1: Most basic, but also the most common usage, enter a number:#include Input: 2[return]3[carriage return]Output: 5Note that:>> will filter out invisible characters (such as Space return, TAB, etc.)cin>>noskipws>>input[j];//don't want to skip whitespace characters, use NOSKIPWS flow controlUsage 2: Accept a string, the "Space", "tab", "Enter" all end#include Input: JKLJKLJKLOutput: JKLJKLJKLInp
cin of Instream
problems that occur when CIN is in use
CIN uses whitespace (spaces, tabs, and line breaks) to confirm the end of the string when it waits for user input.For example: Enter a Alan Dreeb, then encounter a space, Alan is assigned to the first variable, Dreeb is assigned to the second variable.
int main ()
{
char name[20];
Char favorite[20];
The standard output stream in the C ++ programming language interchange stream, which must be supported by iostream. h. Read as "c out ".Directory
ExampleCase AnalysisSkill ApplicationCout ControllerOther informationExample # include Using namespace std;Int main (){Int;Cout Cin>;Cout Return 0;}The number entered by the user is saved by cin in variable a and output through cout.# Include Using namespace std;
Tag: cin cout TimeoutWhen doing the nine-degree problem, due to the large amount of data, in many cases you have to use scanf and printf instead of CIN and cout for input and output, or it will be an error timeout can not AC.There are three recommendations for increasing the input and output speed of C + +:
At the first line in main Function,add:std::ios_base::sync_with_stdio (false). Which cancel
Problem
Recently I encountered such a problem in C ++, while (CIN> S) {}, which of the following types of input can be used to end the running of such a statement, the answer is Ctrl + Z.ProgramEnd. However, there is no profound analysis of the role of Ctrl + Z and the essence of Ctrl + Z. As a result, I found some content and thought I had solved the problem. The learned content is recorded as follows. First, let's take a look at the conditions for
Author: horsetail Source:Http://www.cppblog.com/horsetail/archive/2007/10/18/17814.html Because STD: CIN cannot directly accept spaces (spaces are used as the input flag), we need to use a member function STD: CIN in the CIN object. get () accepts a single character. STD: cout. put () member functions are output directly. as follows: # Include Using namespa
Input format1, cin>>a;
The most basic format, suitable for all types. Will filter out invisible characters such as spaces, TAB, enter, etc.
2, cin>>noskipws>>ch[i];
NOSKIPWS flow control is used, and whitespace characters are not filtered
3, Cin.get (ch), or ch = cin.get ();
Receives a character, similar to GetChar ();
4, Cin.getline (s,k);
Receives
Reference: 62053816/ --------------------------------------------------------------- CIN is the standard input stream object in the C ++ programming language, that is, the object of the istream class. CIN is mainly used to read data from standard input. The standard input here refers to the terminal keyboard. In addition, cout is the object of the stream, that is, the object of the ostream class. cerr is
In the contest, when the large data is encountered, the reading file becomes the bottleneck of the running speed of the program, and it needs a faster reading mode. It is believed that almost all C + + learners have stumbled over the slow speed of the CIN machine, and have vowed not to read the data on the CIN. Others say that the speed of Pascal's read statement is not as scanf as C + +, C + + players can
In chapter 8, an example is provided, which is very simple, that is, to read the user input and assign it to an int. Here, a judgment is provided, that is, if the user input is not an int, cin will become invalid, and there will be a condition state, so we can catch this state and clear, and then continue to read.
However, the example in the book has an error. The original program is as follows:
Code: select all
#include #include using na
Baidu Cin::sync (), the majority of the interpretation is used to clear the buffer, and declare the general and Cin::clear () function together to achieve the purpose.The same way Baidu clears the buffer, and most of it says to use Cin::sync () to achieve this goal. However, Cin::sync () is not used to clear the b
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.