public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* How to hook "std::cin"?
@ 2020-10-29  2:34 孙世龙 sunshilong
  2020-10-29  9:03 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: 孙世龙 sunshilong @ 2020-10-29  2:34 UTC (permalink / raw)
  To: libstdc++

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?
I would be grateful to have some help with this question.

Best Regards
Sunshilong

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to hook "std::cin"?
  2020-10-29  2:34 How to hook "std::cin"? 孙世龙 sunshilong
@ 2020-10-29  9:03 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2020-10-29  9:03 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: libstdc++

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-29  9:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29  2:34 How to hook "std::cin"? 孙世龙 sunshilong
2020-10-29  9:03 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).