代码如下:其中ZJ::open_max返回系统允许的打开的文件的最大个数

#include "util.h"

#include <unistd.h> // int close(int fd);
#include <iostream>

int main(void)
{
    const long opmax = ZJ::open_max();
    std::cout << "opmax = " << opmax << std::endl;
    for (int i = 0; i < opmax; ++i) {
        std::cout << "close file " << i << ": " << close(i) << std::endl;
    }
    return 0;
}

假设返回的opmax值是1024

但运行结果是:

opmax = 1024
close file 0: 0

为什么?

大哥,close(0)就把cout给关闭了啊!

相关文章:

  • 2022-12-23
  • 2021-07-04
  • 2021-11-15
  • 2022-01-30
  • 2021-11-11
  • 2021-11-18
  • 2022-12-23
猜你喜欢
  • 2021-08-14
  • 2021-07-18
  • 2021-04-16
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-02-24
相关资源
相似解决方案