gpt4 book ai didi

c++ - fopen打开文件失败是什么原因

转载 作者:太空狗 更新时间:2023-10-29 17:20:48 27 4
gpt4 key购买 nike

我在尝试打开文本文件时使用了以下代码。

char frd[32]="word-list.txt";
FILE *rd=fopen(frd,"rb");
if(!rd)
std::cout<<"Coudn't open file\t"<<frd;

我用的是vc 2010,文件在这个项目的debug目录下。谁能告诉我为什么它无法打开文件?

最佳答案

#include<stdio.h>
#include <errno.h>

int main()
{
errno = 0;
FILE *fb = fopen("/home/jeegar/filename","r");
if(fb==NULL)
printf("its null");
else
printf("working");


printf("Error %d \n", errno);


}

如果 fopen 失败,那么它将设置错误编号,您可以在此处找到这些错误编号列表 http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html

关于c++ - fopen打开文件失败是什么原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8633909/

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