How to asynchronously read input from command line using boost asio in Windows?

后端 未结 3 1087
萌比男神i
萌比男神i 2020-12-29 14:02

I found this question which asks how to read input asynchronously, but will only work with POSIX stream descriptors, which won\'t work on Windows. So, I found this tutorial

3条回答
  •  旧时难觅i
    2020-12-29 14:42

    You need to initialize your stream_handle to the console input handle. You can't use the same stream_handle for input and for output because those are two different handles.

    For input:

        Example()
            : /* ... */ input_handle( io_service, GetStdHandle(STD_INPUT_HANDLE) )
    

    For output you would use CONSOLE_OUTPUT_HANDLE. But that is probably overkill, you're unlikely to be pushing that much data into stdout on windows that you'd need to use an async write.

提交回复
热议问题