Print string in console, not working c++

I’ve tried serveral things but none seem to work.
I’m trying to print a log to the console



string debug_text = "Distance x: " + to_string(distanceToPlayerX) + ", Distance y: " + to_string(distancetoPlayerY);
FString debug(debug_text.c_str());
UE_LOG(LogClass, Log, TEXT("%s"),debug_text);


I’ve tried both debugging with FString and string, and none of those work.

I got the following error:


CompilerResultsLog:Error: Error D:\Users\\Documents\School\2016-2017\Project\TestProjects\TestShooter\Source\TestShooter\Pickup.cpp(56) : note: see reference to function template instantiation 'void FMsg::Logf_Internal<std::string>(const ANSICHAR *,int32,const FName &,ELogVerbosity::Type,const TCHAR *,T1)' being compiled

Should probably be *debug_text.

Or you could just use one line:



UE_LOG(LogClass, Log, TEXT(""Distance x: %f, y: %f"), distanceToPlayerX, distancetoPlayerY);


I’ve tried what you said


	
string debug_text = "Distance x: " + to_string(distanceToPlayerX) + ", Distance y: " + to_string(distancetoPlayerY);
	
FString debug(debug_text.c_str());



UE_LOG(LogClass, Log, TEXT("%s",*debug_string));

-> this gives me this error when compiling = CompilerResultsLog:Error: Error D:\Users\Documents\School\2016-2017\Project\TestProjects\TestShooter\Source\TestShooter\Pickup.cpp(56) : error C4002: too many actual parameters for macro ‘TEXT’
I’ve tried with *debug_string and *debug

If I do it in one line without a string it works. Why doesnt %s work?

Bracket is in the wrong place. The TEXT macro should only wrap around the actual text not the params.

UE_LOG(LogClass, Log, TEXT(“%s”),*debug_string);