相关疑难解决方法(0)

如何实现getline()的超时?

我想getline()在c ++中从命令行读取一个字符串.

为此,我想添加5秒的计时器.如果没有读取字符串,则程序将终止.

我怎样才能做到这一点?

c++ gcc centos

7
推荐指数
2
解决办法
3800
查看次数

如何在C++中使用计时器在给定时间内强制输入?

我想在C++中实现超时功能.

如果用户未在2秒内输入该值,则程序必须显示超时语句并再次询问输入

EX(输出屏幕):

Timer=0;  
Please enter the input:       //if input is not given within 2 seconds then  
Time-out: 2 seconds  
Timer again set to 0  
Please enter the input:  //if input is not given within 2 seconds then  
Time-out: 2 seconds  
Timer again set to 0  
Please enter the input:22  
Data accepted  
Terminate the program`
Run Code Online (Sandbox Code Playgroud)

码:

#include<iostream>  
 #include<time.h>  
 using namespace std;  
 int main()  
{  
    clock_t endwait;  
    endwait =  2000 ;  
   cout<<endwait;  
   while (clock() < endwait)  
  {  
         cout<<"Please enter the input:"; …
Run Code Online (Sandbox Code Playgroud)

c++ timer sliding-window

7
推荐指数
1
解决办法
2万
查看次数

在stdin中使用boost :: asio :: async_read?

简短的问题:我有一个实时模拟,它作为一个背景过程运行,并与管道连接到调用pogramm.我想使用stdin向该进程发送命令,以通过stdout从中获取某些信息.现在因为它是一个实时过程,它必须是一个非阻塞输入.boost :: asio :: async_read和iostream :: cin一起使用这个任务是个好主意吗?如果可行,我该如何使用该功能?还有什么建议吗?

c++ boost iostream asynchronous boost-asio

5
推荐指数
1
解决办法
5837
查看次数

在C++中设置ifstream的超时?

我们试图从连接到linux盒子的2 usb鼠标中读取数据(这些数据用于机器人的测距/定位).所以我们需要不断地从每只鼠标中读取它移动了多少.问题是当鼠标没有移动时,它不会发送任何数据,因此我们从中获取数据块的文件流,因此程序无法进行里程计算(其中涉及速度的时间测量) .

有没有办法在输入流上设置超时(我们在C++中使用ifstream并从/ dev/input/mouse读取),这样我们就可以知道鼠标何时不移动,而不是等待要收到的活动?或者我们需要搞乱线程(arggh ......)?欢迎任何其他建议!

提前致谢!

c++ linux mouse input

3
推荐指数
2
解决办法
3601
查看次数

标签 统计

c++ ×4

asynchronous ×1

boost ×1

boost-asio ×1

centos ×1

gcc ×1

input ×1

iostream ×1

linux ×1

mouse ×1

sliding-window ×1

timer ×1