# TString form function with TString or string variable

**URL:** <https://root-forum.cern.ch/t/tstring-form-function-with-tstring-or-string-variable/62771>\
**Category:** Newbie\
**Created:** [January 27, 2025, 1:57pm UTC](https://root-forum.cern.ch/t/tstring-form-function-with-tstring-or-string-variable/62771 "2025-01-27T13:57:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ygr](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/f0a364/32.png) [@ygr](https://root-forum.cern.ch/u/ygr)\
**Post date:** [January 27, 2025, 1:57pm UTC](https://root-forum.cern.ch/t/tstring-form-function-with-tstring-or-string-variable/62771/1 "2025-01-27T13:57:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 27, 2025, 2:39pm UTC](https://root-forum.cern.ch/t/tstring-form-function-with-tstring-or-string-variable/62771/2 "2025-01-27T14:39:01Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![ygr](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/f0a364/32.png) [@ygr](https://root-forum.cern.ch/u/ygr)\
**Post date:** [January 27, 2025, 2:46pm UTC](https://root-forum.cern.ch/t/tstring-form-function-with-tstring-or-string-variable/62771/3 "2025-01-27T14:46:07Z")

</div>

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.
