How can I redirect stdin (istream) to wxWidgets?

I am trying to figure out how to redirect istream to wxwidgets.

I was able to redirect ostream, here's how (so you know what I mean):

wxTextCtrl* stdoutctrl = new wxTextCtrl(...); wxStreamToTextRedirector redirect(stdoutctrl); //Redirect ostream std::cout<<"stdout -- does this work?"<<std::endl; //It worked. 

Iโ€™ve searched somewhere already, and I canโ€™t find out that I am redirecting istream to some wx input (so that โ€œcinโ€ is actually asking the user for input via wxWidgets).

+4
source share
1 answer

No, there is no built-in way to do this, since it is much less often required to redirect cin like this compared to cout . And itโ€™s also not entirely clear how you expect this to work, i.e. You probably can't just map it to wxTextCtrl , as you do with cout . And in general, reading is a locking operation, as opposed to writing, so itโ€™s completely unclear how you can structure your GUI application for this.

In short, I donโ€™t think you can port your console program using cin to wxWidgets, as it is at all.

+3
source

Source: https://habr.com/ru/post/1304212/


All Articles