From: Jonathan Wakely <jwakely@redhat.com>
To: "孙世龙 sunshilong" <sunshilong369@gmail.com>
Cc: libstdc++ <libstdc++@gcc.gnu.org>
Subject: Re: How to hook "std::cin"?
Date: Thu, 29 Oct 2020 09:03:24 +0000 [thread overview]
Message-ID: <20201029090324.GA503596@redhat.com> (raw)
In-Reply-To: <CAAvDm6Z5oJ8Nk13=JQ3x9pk0_hCBdnfoQ1049ZL93tXsAEkFjw@mail.gmail.com>
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.
prev parent reply other threads:[~2020-10-29 9:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 2:34 孙世龙 sunshilong
2020-10-29 9:03 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201029090324.GA503596@redhat.com \
--to=jwakely@redhat.com \
--cc=libstdc++@gcc.gnu.org \
--cc=sunshilong369@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).