是在接近标准输入/ FCLOSE保证是正确的? [英] Is close/fclose on stdin guaranteed to be correct?
问题描述
这好像下面的调用做你所期望(关闭流,不允许任何进一步的输入 - 任何等待的流将返回错误输入),但是它保证在所有的编译器/平台正确?
关闭(的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屋!