# How to print string with append node in C++?

**URL:** <https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE4, CPP, question\
**Created:** [August 3, 2022, 2:15pm UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608 "2022-08-03T14:15:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 2:15pm UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/1 "2022-08-03T14:15:27Z")

</div>

Hello, I want to print string in C++ using the same method as in this blueprint code.

 ![image_2022-08-03_191453657](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/9/b4932977f5ba89ea82e6a63f4c1e1a99a71feac0.png)  
How can I achieve this? Thank you

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 2:24pm UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/2 "2022-08-03T14:24:12Z")

</div>

what I am doing is 😃  
I don’t want to use kismet library

```auto
FString StrRet1{};
FString StrRet2{};
FString StrRet3{};
FString StrRet4{};
FString StrRet5{};
StrRet1 = UKismetStringLibrary::Concat_StrStr(StrRet1, FString(TEXT(One)));
StrRet2 = UKismetStringLibrary::Concat_StrStr(StrRet2, FString(TEXT(__)));
StrRet3 = UKismetStringLibrary::Concat_StrStr(StrRet3, FString(TEXT(Two)));
StrRet4 = UKismetStringLibrary::Concat_StrStr(StrRet4, FString(TEXT(__)));
StrRet5 = UKismetStringLibrary::Concat_StrStr(StrRet5, FString(TEXT(Three)));
UKismetSystemLibrary::PrintString(this, StrRet4, true, true, FLinearColor(0.000000,0.660000,1.000000,1.000000), 2.000000);

```

---

<div class="post-metadata">

**Author:** ![IrSoil](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IrSoil](https://forums.unrealengine.com/u/IrSoil)\
**Post date:** [August 3, 2022, 11:37pm UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/3 "2022-08-03T23:37:28Z")

</div>

The proper way would be to use `+` operator:

```c++
FString Str1 = "One";
FString Str2 = "Two";
FString Str3 = "Three";
FString Message = Str1 + " __" + Str2 + "__" + Str3;
//Without kismet onscreen printing can be done the following way. "GEngine" is a global variable. Note that this function doesn't print to console
GEngine->AddOnscreenDebugMessage(-1, 10, FColor::Cyan, Message);

```

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 4, 2022, 12:07am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/4 "2022-08-04T00:07:03Z")

</div>

```auto
FStringFormatOrderedArguments LogArguments;
LogArguments.Add(StringVariable1);
LogArguments.Add(StringVariable2);
LogArguments.Add(StringVariable3);
FString LogString = FString::Format(TEXT("%s %s %s"), LogArguments);
GEngine->AddOnScreenDebugMessage((uint64)-1, 5.f, FColor::White, *LogString);

```

---

<div class="post-metadata">

**Author:** ![KaidoomDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaidoomdev/32/977996_2.png) [@KaidoomDev](https://forums.unrealengine.com/u/KaidoomDev)\
**Post date:** [August 4, 2022, 4:10am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/5 "2022-08-04T04:10:15Z")

</div>

What’s wrong with kismet library ?

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 4, 2022, 4:16am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/6 "2022-08-04T04:16:59Z")

</div>

so its mean I can create a macro for this to make life easier?

```auto
FStringFormatOrderedArguments LogArguments;
LogArguments.Add(StringVariable1);
LogArguments.Add(StringVariable2);
LogArguments.Add(StringVariable3);

```

macro  
`#define LogString(Format, ...) if(GEngine){GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, FString::LogString(TEXT(Format), ## __VA_ARGS__ ), false);}`

call  
LogString (“%s \_ %s \_ %s”, LogArguments);

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 4, 2022, 4:19am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/7 "2022-08-04T04:19:29Z")

</div>

kismet library is very cool, but I am learning pure C++ for UE4 and I just don’t want to use blueprint libraries incase if everything is slightly easy to do in pure C++, but yes sometimes I do use if things goes very complicated

---

<div class="post-metadata">

**Author:** ![KaidoomDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaidoomdev/32/977996_2.png) [@KaidoomDev](https://forums.unrealengine.com/u/KaidoomDev)\
**Post date:** [August 4, 2022, 5:17am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/8 "2022-08-04T05:17:52Z")

</div>

The thing about working with string is you want to avoid multiple allocations, I know you don’t like Kismet library but it is C++ at the end of the day and if you look at the definition here you can adjust it to multiple strings instead of just 2 and have it append all that in one allocation which should be faster than other methods.

```auto
FString UKismetStringLibrary::Concat_StrStr(const FString& A, const FString& B)
{
	// faster, preallocating method
	FString StringResult;
	StringResult.Empty(A.Len() + B.Len() + 1); // adding one for the string terminator
	StringResult += A;
	StringResult += B;

	return StringResult;
}

```

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 4, 2022, 5:22am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/9 "2022-08-04T05:22:59Z")

</div>

Very Informative , really appreciated 🙂 thank you so much for sharing this expensive information

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 5, 2022, 1:28am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/10 "2022-08-05T01:28:47Z")

</div>

No the example I gave you is fine as is. Macros should be avoided for various reasons.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 5, 2022, 1:52am UTC](https://forums.unrealengine.com/t/how-to-print-string-with-append-node-in-c/620608/11 "2022-08-05T01:52:38Z")

</div>

I will need more time to learn to print strings without macros, they have hard syntax to remember
