FString::Printf
#include "Containers/UnrealString.h"
Access: public
Specifiers: static
Description
Constructs a new FString using printf-style format specifiers. Equivalent to sprintf with automatic memory management.
Signature
static FString Printf( const TCHAR* Fmt, ... ) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Fmt | const TCHAR* | A printf-style format string wrapped in TEXT("..."). | — |
| ... | ... | Arguments matching the format specifiers in Fmt. | — |
Return Type
FString Caveats & Gotchas
- • Always wrap the format string in TEXT("..."): FString::Printf(TEXT("Val: %d"), Value). A narrow string literal will not compile.
- • %s expects a raw TCHAR* — use the dereference operator: FString::Printf(TEXT("%s"), *MyStr). Passing the FString object directly is a bug that may corrupt the stack.
- • For performance-critical code with repeated appends, use FString::Appendf() to avoid allocating a new FString on every call.
Example
Format a player status string C++
FString Status = FString::Printf(
TEXT("%s: HP=%d / Ammo=%d"),
*PlayerName,
CurrentHealth,
CurrentAmmo
); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?