调用 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/