Search code examples
c++c++builderc++builder-2009

Printf used in unfamiliar fashion


I found this line of code when upgrading a C++ Builder project to RAD Studio 2009:

mProcessLength->Text.printf("%d",mStreamLength);

It doesn't compile in 2009, however what is the intent of this line and what is a better equivalent? Given that mProcessLength->Text is now a wchar_t*.


Solution

  • I suspect that you are getting these errors:

    E2034 Cannot convert 'const char *' to 'const wchar_t *'
    E2342 Type mismatch in parameter 'format' (wanted 'const wchar_t *', got 'const char *')
    

    It's the parameters you are passing to printf that are mismatched. Changing it to:

    mProcessLength->Text.printf(L"%d",mStreamLength);
    

    will change your string literal to the correct type.