wxString in acutPrintf

Hi,
I got wxString from wxTextCtrl and try to print it acutPrintf(_T("\n%s."), input->GetLineText(0));
only some chines hieroglyphs are written.

General question.
Which way is best to deal with different strings? wxString AcString std::string
because wxWidgets use wxString
BRX SDK use AcString
Some other libs use std::string

Comments

  • The string returned is a class-string : be it wxString, AcString, CString etc.;
    but all the "printf" formatting options extect a string pointer, and not all classes do provide an automatic conversion/casting ....

    So the most correct solution for wxString :
    acutPrintf(_T("\n%ls"), input->GetLineText(0).c_str());

    similar for AcString : that has ::kwszPtr();
    and CString has similar as well ...

    And all those string classes provide constructors using Unicode plain string pointer (const wchar_t*) ...
    so you can easily "convert" from one string class to another, using the target's class wchar_t based CTor, given the source string .c_str(), or .kwszPtr() etc.

    Note the "%ls", because it is entirely Unicode ! "%s" is for ANSII string, will result in gabage output !
    (probably, in your code sample, using the correct "%ls" can be sufficient, I think MSVC recognises the casting operation from wxString)

    hope this helps ?

  • I did not knew %ls it may been a problem. Because if I entered 10 length string acutPrintf printed good if I entered less I got garbage.
    kwszPtr() is hard to remember.

  • Also, please keep in mind, that BricsCAD (and therefore all the integrated APIs) use Unicode strings ... hence, your wxWidgets build must be Unicode, and all string literals should use the _T("....") notation (for non-WX code), resp. wxT("....") for WX-based code;
    wxStrign can handle both, but automatic ANSI/Unicode conversion can sometimes be problematic, and sometimes the compiler might chose the ANSI version of a wxStrign member function, when the Unicode version is intended
    (then, no conversion will happen, resulting in garbage strings ...)

    many greetings !

  • DonatasAzaravičius
    edited November 2018

    Thanks.

    P.S.
    It looks here some problems by using wxWidgets 3.1.1 so I changed to 3.0.4 version and no problem.

This discussion has been closed.