You would use some async IO library (or use the nitty gritty posix or win32 api yourself if you are masochistic) and use it to create a dispatcher loop.
For example in Boost's asio library you would create a boost::asio::io_service open the streams and start the async_read with a handler that will do what you want and call run on the io_service which will start the dispatcher loop.