开发者

How could I redirect stdin (istream) in wxWidgets?

开发者 https://www.devze.com 2022-12-23 04:32 出处:网络
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):

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号