[转载]fopen_s和errno_t_马鸿凯_新浪博客

原文地址:fopen_s和errno_t 作者:Ma_Hong_Kai

errno_t  fopen_s( FILE** pFile, const char *filename, const char *mode );

说明:pFile 文件指针将接收到打开的文件指针指向的指针

Infilename 文件名

Inmode  允许的访问类型。

返回值:如果成功返回0,失败则返回相应的错误代码。

#include

#include

using namespace std;

int main()

{

FILE  *fin;

 

errno_t err_src_name;

 

char  src_name[128];

 

cout << "输入源文件名:" << endl;

cin >> src_name;

 

// FILE*stream,*stream2;

//Openforread(willfailiffile"crt_fopen_s.c"doesnotexist)

// err = fopen_s(&stream, "crt_fopen_s.c", "r");

 

err_src_name = fopen_s(&fin, src_name, "r");

 

if (err_src_name != 0)

{

cout << "打开文件失败" << endl;

return 0;

 

}

}

注释:

errno_t是一种数据类型,实际上是一个整形,代表错误号码,如果是0就代表没有错误,其他代表抛出一个错误。

头文件:#include  或 #include

下面来一段英文:

error: use of undeclared identifier 'errno_t'  // 不清楚的错误

#include

 

int main(void)

{

errno_t e;

return 0;

}

Which surprisingly raises this error:   // 不可预知的错误

main.c:5:5: error: use of undeclared identifier 'errno_t'

errno_t x;

I started to follow the traces: when the compiler sees the <...> inclusions it will first look at /usr/include where of course I found errno.h file. Actually it has a single line in it, besides the license comment, which is:  // 根据编译器查找错误来源

#include

 

Now, at /usr/include/sys in errno.h I found the following lines:

#include

#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1

#include

#endif

And at /usr/include/_types in _errno_t.h I found this:

typedef int errno_t;

So it looks like, it is there, and it is an alias of the integer type, and part of the errno.h -- just as it should be.

// 最终我们可以看到 是一种数据类型

// typedefC语言关键字,作用是为一种数据类型定义一个新名字。这里的数据类型包括内部数据类型(int,char等)和自定义的数据类型(struct等)

 

是记录学习过程,作为参考!

 

 

 

 

 

 

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ma_Hong_Kai

微信 2936729162

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值