# Why does this string concatenation work?

**URL:** <https://forum.juce.com/t/why-does-this-string-concatenation-work/8445>\
**Category:** General JUCE discussion\
**Created:** [April 10, 2012, 11:27pm UTC](https://forum.juce.com/t/why-does-this-string-concatenation-work/8445 "2012-04-10T23:27:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nonchai](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nonchai/32/1507_2.png) [@nonchai](https://forum.juce.com/u/nonchai)\
**Post date:** [April 10, 2012, 11:27pm UTC](https://forum.juce.com/t/why-does-this-string-concatenation-work/8445/1 "2012-04-10T23:27:56Z")

</div>

in this line i get a compiler error: - "invalid operands char[129] and ‘const char[2]’ t binary [operator+’ "

```auto
          m = findItemByText(prog.multiName+":"+STRING(prog.multiChannelMIDIChannel) ,idx );
```

prog.multiname is just a string and prog.multiChannelMIDIChannel is just an int.

how can i get this to compile ? isn’t it possible to do such simple concatenations with JUCE strings ?

---

<div class="post-metadata">

**Author:** ![andrewj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/andrewj/32/13428_2.png) [@andrewj](https://forum.juce.com/u/andrewj)\
**Post date:** [April 11, 2012, 12:35am UTC](https://forum.juce.com/t/why-does-this-string-concatenation-work/8445/2 "2012-04-11T00:35:06Z")

</div>

What’s STRING()?

---

<div class="post-metadata">

**Author:** ![nonchai](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nonchai/32/1507_2.png) [@nonchai](https://forum.juce.com/u/nonchai)\
**Post date:** [April 11, 2012, 1:29am UTC](https://forum.juce.com/t/why-does-this-string-concatenation-work/8445/3 "2012-04-11T01:29:34Z")

</div>

just a macro for Juce::String

---

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [April 11, 2012, 5:36am UTC](https://forum.juce.com/t/why-does-this-string-concatenation-work/8445/4 "2012-04-11T05:36:46Z")

</div>

> [@](#):
>
> how can i get this to compile ? isn’t it possible to do such simple concatenations with JUCE strings ?

Of course it is possible with JUCE…  
Is your prog.multiname a juce::String…? And your first argument in findItemByText() is a juce::String as well…?

I don’t still understand the STRING macro that you have used… I hope it is simply juce::String(prog.multiChannelMIDIChannel) as it will work nicely for integers…

Try to concatenate into a temp String first and then pass it into your function (just to solve it)… I hope you’ll find out the error…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 11, 2012, 7:47am UTC](https://forum.juce.com/t/why-does-this-string-concatenation-work/8445/5 "2012-04-11T07:47:20Z")

</div>

> [@nonchai](#):
>
> just a macro for Juce::String

Yuck! If you’re really too lazy to type it out, you should at least use a typedef, never a macro!

And according to your error message, prog.multiname is a char\*, so you should make it a String instead.

---

<div class="post-metadata">

**Author:** ![nonchai](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nonchai/32/1507_2.png) [@nonchai](https://forum.juce.com/u/nonchai)\
**Post date:** [April 11, 2012, 1:15pm UTC](https://forum.juce.com/t/why-does-this-string-concatenation-work/8445/6 "2012-04-11T13:15:56Z")

</div>

> [@jules](#):
>
> [quote=“nonchai”]just a macro for Juce::String

Yuck! If you’re really too lazy to type it out, you should at least use a typedef, never a macro!

And according to your error message, prog.multiname is a char\*, so you should make it a String instead.[/quote]

yeah youre right abt macros - mea culpa ! will change that eventually…

And yes - turned out multiname is a char string in a struct - id’ confused it with another property of the same name which IS a Juce::String and thus missed this.

Thanks
