是在接近标准输入/ FCLOSE保证是正确的? [英] Is close/fclose on stdin guaranteed to be correct?

查看:127
本文介绍了是在接近标准输入/ FCLOSE保证是正确的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这好像下面的调用做你所期望(关闭流,不允许任何进一步的输入 - 任何等待的流将返回错误输入),但是它保证在所有的编译器/平台正确?

 关闭(的fileno(标准输入));
FCLOSE(标准输入);


解决方案

没有什么是保证跨每一个可能的操作系统是正确的。但是,调用FCLOSE(标准输入)将任何POSIX兼容的操作系统上工作,以及Windows操作系统,所以你应该打在目前普遍使用pretty多的东西。

正如previous答案以及我的评论指出,没有必要调用close的文件句柄。 FCLOSE()将正确地关闭一切下来给你。

It seems as though the following calls do what you'd expect (close the stream and not allow any further input - anything waiting for input on the stream returns error), but is it guaranteed to be correct across all compilers/platforms?

close(fileno(stdin));
fclose(stdin);

解决方案

Nothing is guaranteed correct across every possible operating system. However, calling fclose(stdin) will work on any POSIX compliant operating system as well as Windows operating systems, so you should hit pretty much anything in general use at the moment.

As stated by the previous answer as well as my comment, there is no need to call close on the file handle. fclose() will properly close everything down for you.

这篇关于是在接近标准输入/ FCLOSE保证是正确的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆