c - 确定 C 中 stdin 大小的正确/有效方法

标签 c size stdin

根据我之前的问题,如果 stdin 来自 pipeterminal,确定 stdin 大小的正确而有效的方法是什么 在不同的系统上。

我正在执行以下操作,但是,根据一些评论,这不是正确的方法,它可能适用于也可能不适用于不同的系统。

#include <sys/stat.h>

off_t size(FILE *st_in) {
    struct stat st;
    if (fstat(fileno(st_in), &st) == 0)
        return st.st_size;
    return -1;
}

最佳答案

你不能。 想象中的标准输入就像一个水龙头。

你问的和“水龙头里有多少水”一样? :-)

关于c - 确定 C 中 stdin 大小的正确/有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4411852/

相关文章:

c++ - C 和 C++ 中 bool 值的 sizeof 运算符的输出差异

python - python子进程的自定义标准输入

c++ - 图像上的 haar 变换

c - 虚拟端口在atmega MCU中运行,可能吗?

go - 为什么一个空 slice 有 24 个字节?

node.js - Node.js 中的标准输入 block

bash - stdin 在管道传输和重定向时表现不同

c - UVa - 最长的午睡

c - lua中宏的使用方法

windows - 从Delphi 6和WinXP到Delphi 2007和Vista/Win7如何处理窗体大小问题