Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在wxWidgets中重定向stdin(istream)?_C++_Wxwidgets_Stdin_Iostream_Istream - Fatal编程技术网

C++ 如何在wxWidgets中重定向stdin(istream)?

C++ 如何在wxWidgets中重定向stdin(istream)?,c++,wxwidgets,stdin,iostream,istream,C++,Wxwidgets,Stdin,Iostream,Istream,我想知道如何将istream重定向到wxwidgets 我能够实现重定向ostream,下面是如何实现的(所以你知道我的意思): wxtxtctrl*stdoutctrl=newwxtxtctrl(…); wxStreamToTextRedirector重定向(stdoutctrl)//重定向ostream std::cout不,没有内置的方法可以做到这一点,因为与cout相比,像这样重定向cin要少得多。而且还不清楚您希望它如何工作,也就是说,您可能无法像使用cout那样将它映射到wxtxtc

我想知道如何将istream重定向到wxwidgets

我能够实现重定向ostream,下面是如何实现的(所以你知道我的意思):

wxtxtctrl*stdoutctrl=newwxtxtctrl(…);
wxStreamToTextRedirector重定向(stdoutctrl)//重定向ostream

std::cout不,没有内置的方法可以做到这一点,因为与
cout
相比,像这样重定向
cin
要少得多。而且还不清楚您希望它如何工作,也就是说,您可能无法像使用
cout
那样将它映射到
wxtxtctrl
。更一般地说,读取是一种阻塞操作,与写入不同,因此根本不清楚如何构造GUI应用程序来执行该操作

简而言之,我认为您根本无法使用
cin
将您的控制台程序移植到像这样的wxWidgets

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