fopen无法打开文件的原因是什么 [英] what is the reason for fopen's failure to open a file

查看:100
本文介绍了fopen无法打开文件的原因是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试打开文本文件的地方,我有以下代码。

I have the following code where I am trying to open a text file.

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

我正在使用vc 2010,该文件位于该项目的debug目录中。
谁能告诉我为什么它无法打开文件?

I am using vc 2010 and the file is in the debug directory of this project. Can anyone tell me why it is not able to open the file?

推荐答案

#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

this way if fopen gets fail then it will set error number you can find those error number list at here http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html

这篇关于fopen无法打开文件的原因是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆