无法在 Visual Studio 中打开源文件 err.h?

标签 c visual-studio

当我在 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/

相关文章:

C:scanf 和 getchar 行为的差异

c - 关于 sigaction 函数

visual-studio - Windows 窗体的窗体和文本框的 Dispose 方法的行为差异

visual-studio - Visual Studio 尝试将父目录文件添加到位于子文件夹中的项目中

c - 如何使用 Intel 内在函数重新排序 128 位 vector ?

c - TCP 套接字传输中字符串的第一个字符丢失 - C

C++ 模板类中函数指针的问题

c++ - Visual Studio 2015 中 Unresolved external symbol 链接器错误

c# - 如何在 winform 上刷新数据驱动的组合框

c - 练习在 printf 函数中使用指针时,程序不断崩溃