TString form function with TString or string variable

I dont know if there has been a solution for this or a simple workaround that I dont know yet.
I have been using TString with its Form function which is quite useful, but when it comes to including string or another TString it does not work.
I’ve figured you can add any type with “+=” operator but its not a convenient solution cos I need to add multiple strings, TStrings and int/float with variating order so using += operator makes it really complicated for each variable addition one by one.
Form function on the other is tidy.
So my question is how can I add string or TString within Form function.

Here is an example I tried but got errors as you can imagine error is
cannot pass non-trivial object of type ‘TString’ to variadic method;

TString aa = “aa”;
TString bb = “bb”;
string cc = “cc”;
aa.Form(“%s”,bb); //error
aa.Form(“%s”,cc); //error
aa.Form(“%c”,bb); //error
aa.Form(“%c”,cc); //error

I want simple to be able to add sth like this
aa.Form(“%s %s %d %f %s”,“mytext”, varstr, varint, varfloat, vartstring)

is that possible?

Yes.
if the first 2 are TString and the last 2 are std::string:

aa.Form(“%s %s %d %f %s”,“mytext”, varstr.Data(), varint.Data(), varfloat.c_str(), vartstring.c_str());
1 Like

Thanks @pcanal, I keep forgetting that c_str() function is needed.
And I have learnt that Data function also providing c_str thanks to you.
Cheers.