I am doing the unreal course and I am currently at the Bulls and Cows section. So far it’s been great but I am not getting how the Printf() function works and why is it used and also what does the %s and %i format specifiers do. I’d be glad if someone explains all these to me in this context. The picture is attached below.
It’s using one of the printf family of functions from C which does formatted output.
FString::Printf
will use printf to create an FString. All of the % specifiers are placeholders and will be replaced by the value of the respective argument
FString::Printf(TEXT("%s %i %f"), TEXT("Hello"), 42, 3.14.f);
^1-------------2---3^
^ replace with float(3)
^ replace with an int(2)
^ replace with string(1),
Would create an FString with the value "Hello 42 3.14"
, the placeholders being positional.
The * is needed for HiddenWord
as it is an FString and not something printf
(function from the C language) knows what to do with; it needs a pointer to a null terminated character array which is what FString::operator*()
does.
You can see a table of the format specifiers and what they do here
Thanks for the explanation, I think I get it now.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.