We should pay enough attention to the significance of the input and output when we can coding,
So, in the following, I will list some sort of the input functions.
1.Scanf ()and Cin>>
It is said that the efficiency of scanf is higher than cin.
Why?
Because the cin has a buffer and when it wants to output data, it will put all of the data into the buffer. untill buffer is full, buffer will write all the data in the disc.
So, we should learn to use
ios::sync_with_stdio(false)
This sentence is useful to improve the efficiency of cin and cout.
2. gets(), cin.getline(),getline()
getline() is forbidden in the exam as it is defined in the head file #include<string>
we recommand gets() due to its compatibility in different platforms. and it also can ignore the parameter of string length.
3. cin.get()
We also should know that this function is dangerous.
it will return an int not a char.
so when we are in the machine implemented by unsigned char, we will find some strange mistakes.
while((ch=cin.get())!=EOF)
This loop cannot be stopped.
PS: we have another way to end the readin of file.
while(~(ch=cin.get())
i cannot figure out its principle. Actually , it can stop the read of the file.