C++ linux c++;libev官方示例显示冗余控制台行为

C++ linux c++;libev官方示例显示冗余控制台行为,c++,linux,input,console,libev,C++,Linux,Input,Console,Libev,我刚刚尝试了libev的官方例子,如下所示。编译和运行之后,我看到一旦我从stdin输入了任何东西,事件就被触发了,没有问题。但我输入的仍然被视为固体输入,然后出现在我的控制台上。我的问题是:有没有办法避免这个控制台输入被提示到控制台,就像libev捕获和存储它一样 利贝夫有没有办法做到这一点 我将官方示例粘贴到这里: // a single header file is required #include <ev.h> #include <stdio

我刚刚尝试了libev的官方例子,如下所示。编译和运行之后,我看到一旦我从stdin输入了任何东西,事件就被触发了,没有问题。但我输入的仍然被视为固体输入,然后出现在我的控制台上。我的问题是:有没有办法避免这个控制台输入被提示到控制台,就像libev捕获和存储它一样

利贝夫有没有办法做到这一点

我将官方示例粘贴到这里:

    // a single header file is required
    #include <ev.h>

    #include <stdio.h> // for puts

    // every watcher type has its own typedef'd struct
    // with the name ev_TYPE
    ev_io stdin_watcher;
    ev_timer timeout_watcher;

    // all watcher callbacks have a similar signature
    // this callback is called when data is readable on stdin
    static void
    stdin_cb (EV_P_ ev_io *w, int revents)
    {
      puts ("stdin ready");
      // for one-shot events, one must manually stop the watcher
      // with its corresponding stop function.
      ev_io_stop (EV_A_ w);

      // this causes all nested ev_run's to stop iterating
      ev_break (EV_A_ EVBREAK_ALL);
    }

    // another callback, this time for a time-out
    static void
    timeout_cb (EV_P_ ev_timer *w, int revents)
    {
      puts ("timeout");
      // this causes the innermost ev_run to stop iterating
      ev_break (EV_A_ EVBREAK_ONE);
    }

    int
    main (void)
    {
      // use the default event loop unless you have special needs
      struct ev_loop *loop = EV_DEFAULT;

      // initialise an io watcher, then start it
      // this one will watch for stdin to become readable
      ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
      ev_io_start (loop, &stdin_watcher);

      // initialise a timer watcher, then start it
      // simple non-repeating 5.5 second timeout
      ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.);
      ev_timer_start (loop, &timeout_watcher);

      // now wait for events to arrive
      ev_run (loop, 0);

      // break was called, so exit
      return 0;
    }
//需要一个头文件
#包括
#包括//for put
//每个观察者类型都有自己的typedef'd结构
//名为ev_TYPE
电动汽车标准观察者;
ev_定时器超时_监视器;
//所有观察者回调都有类似的签名
//当数据在stdin上可读时,调用此回调
静态空隙
标准断路器(EV\U P\UEV\U io*w,内部防护)
{
放置(“标准输入准备就绪”);
//对于一次性事件,必须手动停止观察者
//具有相应的停止功能。
电动停车(电动自动停车);
//这会导致所有嵌套的ev_运行停止迭代
ev_break(ev_A_ev break_ALL);
}
//另一个回调,这次是超时
静态空隙
超时\u cb(EV\u P\uEV\u定时器*w,int revents)
{
看跌期权(“超时”);
//这会导致最内部的ev_运行停止迭代
ev_break(ev_A_ev break_ONE);
}
int
主(空)
{
//除非有特殊需要,否则使用默认事件循环
结构ev_循环*循环=ev_默认值;
//初始化io监视程序,然后启动它
//这一个将监视stdin变得可读
ev_io_init(&stdin_watcher,stdin_cb,/*stdin_FILENO*/0,ev_READ);
ev_io_启动(回路和标准观察装置);
//初始化计时器观察程序,然后启动它
//简单非重复5.5秒超时
ev_timer_init(&timeout_watcher,timeout_cb,5.5,0.);
电动计时器启动(循环、超时和观察);
//现在等待事件的到来
电动汽车运行(循环,0);
//中断被调用,所以退出
返回0;
}

我想你是指你写的东西的回响吧?这是终端程序的默认行为。您可以使用函数和标志来禁用回显。不过,请记住在退出程序之前启用它。

我想你的意思是重复你写的东西?这是终端程序的默认行为。您可以使用函数和标志来禁用回显。不过,请记住在退出程序之前启用它。

ev_io_init
中,您正在设置触发器。例如,您可以选择从套接字使用fd,而不是设置STDIN_FILENO。不知道这是不是你要找的。这里是我所说内容的一部分。

ev\u io\u init
中,您正在设置触发器。例如,您可以选择从套接字使用fd,而不是设置STDIN_FILENO。不知道这是不是你要找的。这是我所说内容的一部分。

您是在问如何禁用console echo吗?您是在问如何禁用console echo吗?