perror(s) 用来将上一个函数发生错误的原因输出到标准设备(stderr)。
参数 s 所指的字符串会先打印出,后面再加上错误原因字符串。
此错误原因依照全局变量errno的值来决定要输出的字符串。
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
FILE *fp;
fp = fopen("/root/gcb/hhh.py", "r+");
if(fp == NULL){
perror("/root/gcb/hhh.py");
}
cout<<endl<<" --- aa ---"<<endl;
}
- 此处注意,执行完 perror 之后,下面的程序还会接着执行。