I am getting result from wxStreamToTextRedirector as one line. The newlines are lost .... wxStreamToTextRedirector with just one parameter supposed to redirect output to cout, I have no clue why the newlines are not treated by cout, as such...
Update: a simplified example: produces the same result i.e newlines are lost.
textctrl = new wxTextCtrl(this, -1, wxT(""), wxPoint(-1, -1),
wxSize(250, 150));
{
wxStreamToTextRedirector redirect(textctrl);
string result = "line1\n Line2\n";
cout << result;
}
Output ---> line1 Line2, as appears in the textctrl window. May it be that textctrl
window does not interpret
\n correctly? I am using wxWidets on a Windows machine.
When creating a wxTextCtrl
, by default it is created without support for multiple lines. You have to tell it that you intend to use multiple lines. If you are using Code::Blocks with wxSmith (which I recommend), you can specify that in the properties of the wxTextCtrl
:
If you are creating it manually with code, you only need to specify wxTE_MULTILINE
in the style parameter of the constructor, like this:
textctrl = new wxTextCtrl(this, -1, wxT(""), wxPoint(-1, -1), wxSize(250, 150),wxTE_MULTILINE);
For more information, you can check this page about the possible styles, and in particular, this section about the constructor.