# String to TString

**URL:** <https://root-forum.cern.ch/t/string-to-tstring/64193>\
**Category:** General Chat\
**Tags:** tree\
**Created:** [September 22, 2025, 9:22am UTC](https://root-forum.cern.ch/t/string-to-tstring/64193 "2025-09-22T09:22:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yordanov](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@yordanov](https://root-forum.cern.ch/u/yordanov)\
**Post date:** [September 22, 2025, 9:22am UTC](https://root-forum.cern.ch/t/string-to-tstring/64193/1 "2025-09-22T09:22:01Z")

</div>

Hello,

I need to copy a string into a TString. Something like:

string line=“aaa”;  
TString name;  
name=line;

However, the last line is not valid. name.Data()=line does not work either. What would be the correct syntaxis?

Many thanks!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 22, 2025, 11:28am UTC](https://root-forum.cern.ch/t/string-to-tstring/64193/2 "2025-09-22T11:28:59Z")

</div>

```auto
{
   string line1 = "aaa";
   printf ("line1 = %s\n",line1.c_str());
   TString line2 = line1.c_str();
   printf ("line2 = %s\n",line2.Data());
}

```

gives:

```auto
$ root string2tstring.C
   ------------------------------------------------------------------
  | Welcome to ROOT 6.37.01 https://root.cern |
  | (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosxarm64 on Sep 22 2025, 08:16:26 |
  | From heads/master@v6-37-01-8233-g4254e9d6d43 |
  | With Apple clang version 17.0.0 (clang-1700.3.19.1) |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

root [0] 
Processing string2tstring.C...
line1 = aaa
line2 = aaa

```

---

<div class="post-metadata">

**Author:** ![yordanov](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@yordanov](https://root-forum.cern.ch/u/yordanov)\
**Post date:** [September 22, 2025, 12:10pm UTC](https://root-forum.cern.ch/t/string-to-tstring/64193/3 "2025-09-22T12:10:55Z")

</div>

c\_str() works fine. Thank you!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 22, 2025, 5:36pm UTC](https://root-forum.cern.ch/t/string-to-tstring/64193/4 "2025-09-22T17:36:56Z")

</div>

It seems to me your ROOT distribution is broken.  
The code snippet from your first post should work.  
[The “`TString(const string& s)`” constructor and the “`TString& operator=(const string& s)`” existed already in ROOT 5.34 (and probably also in some older versions).](https://root.cern/root/html534/TString.html)

---

<div class="post-metadata">

**Author:** ![yordanov](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@yordanov](https://root-forum.cern.ch/u/yordanov)\
**Post date:** [September 22, 2025, 6:22pm UTC](https://root-forum.cern.ch/t/string-to-tstring/64193/5 "2025-09-22T18:22:12Z")

</div>

You are right. I am using 5.28 binaries for windows with VS10, because that is the last stable combination that works under windows from my experience. I made an attempt recently to go to the latest version, but there are problems. See for instance:  
[ROOT on Windows 11 - ROOT - ROOT Forum](https://root-forum.cern.ch/t/root-on-windows-11/62429/12)

Best regards

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 22, 2025, 7:01pm UTC](https://root-forum.cern.ch/t/string-to-tstring/64193/6 "2025-09-22T19:01:21Z")

</div>

Try to build the head of the [`v5-34-00-patches`](https://github.com/root-project/root/tree/v5-34-00-patches) branch.
