How to print data of elements of for each loop? C++

Hi, I want to print the element of a for-each loop in C++, the same way i did in blueprint.

How to do this using my own existing macro?

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

I have a macro to print variables in format
printf("%f", "%d", "%s", float, int, *string);

if I want to print variable data from int32 myInt = 5;
i just printf("%d", myInt); and it prints the value 5 on the screen.
Thank you

the Arr is itself the Array Element returned by the loop, print it to console/screen anywhere you want.

hope it helps, cheers

1 Like

its mean i don’t need to declare an extra returning variable for this? and if the array type is not int but enum then how to print?

enum is basically a set of characters, you can use %c to log it

hope it helps, cheers!

So its mean I can do something like printf("%c", MyEnumArrayRef); ?

yes this %c is the part of the format family you recently used %s, %d, %f …

hope it helps, cheers!

2 Likes

image_2022-08-04_140309716
using %c prints these characters instead of the data stored in the Arr

I am lost :tired_face:

I think this is not related to %c , the characters are printed if there is no data in the array becasue your PercentRoll needs an entry on each row according to your algorithm you posted in the previous post

hope it helps, cheers!

2 Likes

The data is in here in the data table and I am extracting and storing it in the data table like

        //trying to print the data already extracted from the data table
		for (auto& Array : Arr) //For each loop
				{
					printf("%c", Array); //print the variable data
				}
				print("_____________"); //print the inserted text
				ItemType = Arr[FMath::RandRange(0, 99)]; 

main question is already answered you asked about logging the elements, for any new question open a new thread with maximum details as you can and if you have the code working in blueprint please post the high resolution image of it along with the C++ code you are trying… it will be easy easy and quick for us to debug your code instead of writing it from scratch.

hope it helps, cheers!

1 Like

sure, and thank you for your precious time spending in solving the problems , really appreciated :slight_smile:

1 Like