gpt4 book ai didi

c++ - 初学者 C++ 指针

转载 作者:行者123 更新时间:2023-11-30 05:30:14 25 4
gpt4 key购买 nike

我在阅读代码片段时看到了这个

FILE * infile = fopen("input.wav","rb");

我想在这里问 2 个问题。

  1. 这里的FILE是什么。它是类、对象还是其他任何东西。

  2. infile 指向什么。我已经看到指向 int、char 等的指针。但是那指向什么。

最佳答案

What is FILE here. Is it a class, object or anything else?

  • FILE 是一个对象,它标识一个流并包含控制它所需的信息,即位置指示器、指向缓冲区的指针和所有状态指示器。

  • fopen 返回指向 FILE 对象的指针。

  • FILE 对象的内存分配是自动管理的,即当使用 fclose 关闭流时(或程序终止时),库负责释放资源通常)。

  • 如果包含 头文件,将自动创建这三个 FILE 对象:

    1. stdin:标准输入流
    2. stdout:标准输出流
    3. stderr:标准错误流

What is infile pointing to. I have seen pointers to int, char etc. But what is that pointing to?

它指向那个 FILE 对象。

如果你想从那个文件指针读取,做这样的事情:

if (infile == NULL) perror ("Error opening file");
else { /* read */ }

关于c++ - 初学者 C++ 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36057393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com