I'm trying to figure out how to redirect istream to wxwidgets.
I was able to accomplish redirecting ostream, here's how (so you know what I mean):
wxTextCtrl* stdoutctrl = n开发者_运维技巧ew wxTextCtrl(...);
wxStreamToTextRedirector redirect(stdoutctrl); //Redirect ostream
std::cout<<"stdout -- does this work?"<<std::endl; //It worked.
I've been searching for sometime now, and I'm unable to find out I'd redirect istream to some sort of wx-input (so a "cin" would actually prompt the user for input via wxWidgets).
No, there is no built in way to do this as it's much less common to want to redirect cin
like this compared to cout
. And it's also not really clear how do you expect it to work, i.e. you probably can't just map it to a wxTextCtrl
as you do with cout
. And more generally, reading is a blocking operation, unlike writing, so it's not clear at all how can you structure your GUI application to do it.
In short, I don't think you can port your console program using cin
to wxWidgets like this at all.
精彩评论