How to hook "std::cin"?
Jonathan Wakely
jwakely@redhat.com
Thu Oct 29 09:03:24 GMT 2020
On 29/10/20 10:34 +0800, 孙世龙 sunshilong via Libstdc++ wrote:
>Hi, list
>
>I want "std::cin >> str" to behave as follows on Linux:
>1. sleep for a second;
>2.return a specific string, e.g: "hello, world".
>
>How to achieve this goal?
You can write a custom streambuf that sleeps in its underflow()
member, then fills the get area with that specific string.
Then replace std::cin's stream buffer with your custom one.
More information about the Libstdc++
mailing list