C++输出错误信息perror、strerror以及全局变量errno
2024-09-01 03:34:52
头文件:#include<stdio.h>
函数:perror、strerror,全局变量:errno。
使用方法:
FILE *fp;
if((fp = fopen("test.txt", "r")) == NULL)
{
perror("test.txt open error");
printf("%s\n",strerror(errno));
printf("%d\n",errno);
exit();
}
输出:
output: test.txt open error: No such file or directory
No such file or directory
errno是一个int型的全局变量,它(编码成错误编号)返回函数的错误信息(C/C++的库函数大都是有返回值的,以便调用者知道该函数的执行结果),例如上例的错误信息:2
最新文章
- git操作的常用命令
- 11个提问频率最高的PHP面试题
- 妙用Javascript中apply、call、bind
- Delphi ActiveX Form的使用实例
- memcache 开发版
- Delegate 委托复习(-) 委托的基本概念
- Nginx配置同一个域名http与https两种方式都可访问
- [iOS]C语言技术视频-02-程序分支结构(if...else)
- [2017.02.21] 《Haskell趣学指南 —— Learning You a Haskell for Great Good!》
- git生成ssh key及github ssh key对接
- path和classpath的区别
- asp.net 按钮执行前后台方法——前台弹出提示信息,确认后继续执行后台方法,取消则不执行后台方法
- Java中单例实现
- js 中prototype运用(数组)
- matlab练习程序(点云下采样)
- 浅析原生js模仿addclass和removeclass
- iOS耳机监听
- 基于Boost库的HTTP Post函数
- Skype for Business Server-呼叫质量仪表板(一)安装与配置
- java后台接收json数据,报错com.alibaba.fastjson.JSONObject cannot be cast to xxx