当我在 Mac 上运行程序时,它运行得很好,但是当我使用 Visual Studio 运行程序时,我收到此错误:
Cannot open source file err.h
是否有其他方法可以处理 Visual Studio 中的错误,或者我没有正确调用?
#include <err.h>
这是我尝试在代码中使用 err 的方法:
switch (select(1, &readfds, NULL, NULL, &tmo)) {
case -1:
err(1, "select"); // This throw an error
break;
case 0:
printf("You did not enter your password within 5 seconds\n");
return (1);
break;
}
最佳答案
整个<err.h>
(与 err()
、 errx()
、 warnx
等)实际上是一个 BSD 事物,@EdHeal。
Linux adopted it ——聪明地。微软并没有——愚蠢地。随着<sysexits.h>
这是一个非常方便的 API,适用于正确的命令行实用程序。
如果您只有一个err()
在程序中调用,你可以将其替换为:
#include <errno.h>
#include <stdio.h>
#include <string.h>
...
fprintf(stderr, "%s: select: %s\n", argv[0], strerror(errno));
exit(1)`.
关于无法在 Visual Studio 中打开源文件 err.h?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51942394/