c++ - 如何使用 errorno 和 _get_errno?

标签 c++ c windows winapi

调用 system()运行外部 .exe 并在出错时检查错误代码:

#include <errno.h>       
#include <stdlib.h>

function()
{
    errno_t err;


      if( system(tailCmd) == -1) //if there is an error get errno
      {
          //Error calling tail.exe 
          _get_errno( &err );  

      }
}

前两个编译错误:

error C2065: 'err' : undeclared identifier
error C2065: 'errno_t' : undeclared identifier

不确定为什么要包括 required and optional header files ?
任何帮助表示赞赏。谢谢。

最佳答案

一个典型的用法是这样的:

if (somecall() == -1) {
    int errsv = errno;
    printf("somecall() failed\n");
    if (errsv == ...) { ... }
}

取自here .

关于c++ - 如何使用 errorno 和 _get_errno?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2270047/

相关文章:

用于制作 GUI 的 C++ 库

c++ - 对临时对象的 const 引用在函数作用域(生命周期)后被破坏

c - 如何计算衰减平均值?

Windows 可执行文件结构

android - 我们不能在 Android Studio 中单独启动模拟器吗?

C++ 编译。翻译阶段#1。通用字符名称

c++ - shared_ptr<Base> 和派生类的对象

c - 如何在没有指数的情况下显示 double ?

c - 结构的大小不等于其内容的大小

windows - 如何使用 Node 的调试模块(Windows)?