Defining Mediums with a loop

Hello everybody,

I try to build mediums with a loop.
For the moment, i was using this syntax: example:

But i have to define a list of mediums.
I tried the following syntax but it does not work

TGeoMedium *med[10]; for(int i=0; i<10;i++){ *med[i] = new TGeoMedium("med"+i, 1, vacuum); }

Could you please explain me what is the syntax in a loop ?

Thank you in advance.

Instead of:
(TString::Format(“med_%i”, i)).Data()

BTW. Do try also:
root [0] "med"
root [1] “med”+0
root [2] “med”+1
root [3] “med”+2
root [4] “med”+3
but do NOT try “med”+4, “med”+5, …

I tried the following syntax:

TGeoMedium *med[10]; for(int i=0; i<10;i++){ *med[i] = new TGeoMedium((TString::Format("med_%i", i)).Data(), 1, vacuum); }

I have the same error: *** Break *** segmentation violation

{ TGeoMaterial *vacuum = new TGeoMaterial("vacuum", 0.0, 0.0, 0.0); TGeoMedium *med[10]; for(int i=0; i<10;i++) med[i] = new TGeoMedium((TString::Format("med_%i", i)).Data(), (i + 1), vacuum); gGeoManager->GetListOfMaterials()->Print(); gGeoManager->GetListOfMedia()->Print(); }

Thank you very much,

It works.