首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >编译代码中未解释的“无此类文件或目录”

编译代码中未解释的“无此类文件或目录”
EN

Stack Overflow用户
提问于 2019-05-25 18:38:26
回答 1查看 101关注 0票数 0

以下复制和修改的代码读取空格键以激活从附加的测试设备中捕获的数据。如果没有下面总结的中间代码,它就运行得很好。通过创建kbrd名称空间并只使用我需要的标准命令,我避免了“使用命名空间std”。代码编译没有困难,但是当我用捕获键盘数据和初始化测试设备所需的代码运行它时,它会运行到"Check point Alpha“并等待。当我按空格键(或任何其他键!)时,它会打印:

检查点Beta没有这样的文件或目录。

非常类似的代码使用鼠标左键收集数据,按预期运行。我正在建造一台小型计算机,使用“纸”显示器在户外便携式使用,并希望有代码不需要鼠标.

为了解决这个问题,我已经用光了。我们请求您的帮助,我们将不胜感激。

代码语言:javascript
运行
复制
    #include <stdlib.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <linux/input.h>
    #include <string.h>
    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <signal.h>
    #include <float.h>
    #include <sa_api.h>
    #pragma comment(lib,"sa_api.lib")
    #undef max
    #undef min

   namespace kbrd{   
     const char *dev = "/dev/input/event3";
     struct input_event ev;
     ssize_t n;
     int fd;}

   using std::cin;
   using std::cout;
   using std::__cxx11::string;
   using std::endl;
   using std::ofstream;
   using std::ios;

   int main(void)
   {
    [[Code which 
      Initiates equipment API, prompts screen & reads keyboard to 
      gather details to be stored with data from attached test 
      equipment...]]`

    while (N_az <Num_Samples) {

      kbrd::fd = open(kbrd::dev, O_RDONLY);
      if (kbrd::fd == -1) {
        fprintf(stderr, "Cannot open %s: %s.\n", kbrd::dev, 
        strerror(errno));
        return EXIT_FAILURE;
      }
      //and then read keyboard events from the device:
      cout << "Check Point Alpha" << endl;
      while (1) {
        kbrd::n = read(kbrd::fd, &kbrd::ev, sizeof kbrd::ev);
        if (kbrd::n == (ssize_t)-1) {
          if (errno == EINTR)
            continue;
          else
            break;
        } else
        if (kbrd::n != sizeof kbrd::ev) {
          errno = EIO;
          break;
        }
        cout << "Check Point Beta" << endl;

        if (kbrd::ev.type == EV_KEY && kbrd::ev.value == 0 /*&& 
            kbrd::ev.value <= 2 */&& kbrd::ev.code == 57){
          cout << "Check Point Charlie" << endl;            

          continue;

          [[ Code to read attached test gear & store data, one point at a 
             time...]]

          N_az = N_az + 1;
        }
        else {
          fflush(stdout);
          fprintf(stderr, "%s.\n", strerror(errno));
          return EXIT_FAILURE;
        }
      }
    } 

   return EXIT_SUCCESS;
 }
EN

回答 1

Stack Overflow用户

发布于 2019-05-26 09:26:04

当我按空格键(或任何其他键!)时,它会打印: 检查点Beta没有这样的文件或目录。

因为你的代码是

cout << "Check Point Beta" << endl; if (kbrd::ev.type == EV\_KEY && kbrd::ev.value == 0 /\*&& kbrd::ev.value <= 2 \*/&& kbrd::ev.code == 57){ cout << "Check Point Charlie" << endl; ... } else { fflush(stdout); fprintf(stderr, "%s.\n", strerror(errno)); return EXIT\_FAILURE; }

这意味着(kbrd::ev.type == EV_KEY && kbrd::ev.value == 0 /*&& kbrd::ev.value <= 2 */&& kbrd::ev.code == 57)是假的,没有这样的文件或目录来自strerror,所以您以前在某个地方有一个错误,并且可能没有在读取中,在读取之前将errno重置为0。警告没有错误时,errno不会重置为0,只有在发生错误时才会设置,因此将其重置为0是您的责任。

只需在测试前临时编写kbrd::ev.type / kbrd::ev.value / kbrd::ev.code的值,然后运行程序,以了解按空格键时的值是什么,从而可以修改代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56307702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档