I have a structure as below, Similarly there could multiple structures with multiple fields.
struct A
{
int a;
int b;
char * c;
float d
};
Now if I want to print each field of the above struct I need to manually type,
cout << A.a << endl;
cout << A.b << endl;
cout << A.c << endl;
cout << A.d << endl;
As you can see the above stuff is manually and repeated task, Is there any way we can auto genearate the above things. If anyone can provide code template for eclipse then that would be useful.
I think you can just create a method in the struct A
that prints all the members. Call it wherever you need to print all the data using A.PrintInternalData()
.
#include<iostream>
struct A
{
int a;
int b;
char * c;
float d
void PrintInternalData()
{
std::cout<<A.a<<std::endl;
std::cout<<A.b<<std::endl;
std::cout<<A.c<<std::endl;
std::cout<<A.d<<std::endl;
}
};