catopen无法使用相同的设置在不同的服务器上打开相同的cat文件。

当errno为0时,这意味着我的理解没有错误。

请告诉我,如果有人以前见过这样的。如果有人知道它发生的原因,这对我很有帮助

我写的示例代码

int main()
{

   nl_catd cat;

   string fileName;

   cout<<"Enter the cat file name: ";

   cin>>fileName;

   cat = catopen(fileName.c_str(), 0);

   if (cat == (nl_catd)-1)

   {

      cerr << "Unable to open catalogue: " << fileName <<" ....and the Error number: "<<errno<<"\n";

      exit(1);

   }

   printf("File opened...\n");

   catclose( cat );

   exit(0);

}

上述代码的输出

成功个案:

./a.out

Enter the cat file name: LinkMonitor.epod.cat

File opened...

对于faliure案例:

./a.out

Enter the cat file name: ehap_ac_in.epod.cat

Unable to open catalogue: ehap_ac_in.epod.cat0

这里0是错误代码。

有帮助吗?

解决方案

你没问题了 errno 当你写的字符串 "Unable to open catalogue: "cerr.

你必须保存的价值 errno 马上。

cat = catopen(fileName.c_str(), 0); 

if (cat == (nl_catd)-1) 

{ 
   int errno_catopen = errno;
   cerr << "Unable to open catalogue: " << fileName <<" ....and the Error number: "<<errno_catopen <<"\n";
   exit(errno_catopen);
} 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top