标签:created argc ret argv string sys 文件 types 类型
Unix errno值、
#include <iostream> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <errno.h>
#include <string.h> int main(int argc, char **argv) { int sockfd = 0; if ((sockfd = socket(0, SOCK_STREAM, 0)) < 0) { if (errno >= 0 && errno <= sys_nerr) printf("socket created, failed[%d], reason:%s\n", errno, sys_errlist[errno]);
printf("%s\n",strerror(errno)); //头文件string.h内 } else { printf("socket successful\n"); } return 0; }
输出结果:
socket created, failed[97], reason:Address family not supported by protocol
Address family not supported by protocol
标签:created argc ret argv string sys 文件 types 类型
原文地址:https://www.cnblogs.com/weiyouqing/p/13055203.html