TA lessons about the input and the output

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.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值