Setting names for integers using char and sprintf


I would like to set some integers, Is what I follow correct ?

char int_name[50]; float fraction=0.1; correlation=0.9; sprintf(c_name"x=%g_cor=%g",fraction,correlation);
So, if I now do

int c_name

what will be the result? The integer will be named after


or it will be named just “c_name” ?

Is this the correct way to set integers /floats by using a name containing some other variables ?

Thanks in advance



It would be named c_name.sprintf(c_name"x=%g_cor=%g",fraction,correlation)is not valid C++ (nor any CINT extension). (i.e. the part c_name"x=%g_cor=%g" is meaningless in C++).x=0.1_cor=.09is an invalid C++ symbol name (can’t contain any dot not equal signs.

In which contain do you want/need to set the name of variable to such values?


Actually, I do not care to include the equal or dot …
What I want to do is to make several TGraphs but each one depends one 3 variables, call them fraction,correlation,epsilon values

so, I want to make vectors, named after these variables (actually following their values somehow) and following something like

vector< vector < pair <float, float > > > values_per_frac_0.1_cor_0.5_eps_1.5;


vector< pair <float, float > > values_per_cor_0.5_eps_1.5;

so, it will be really easy them to have one TGraph (or whatever I need to plot) by calling the proper vector while looping inside afterwards…

So, is there any way to declare and them “call” vectors by using some kind of char + sprinft syntax??

Thanks again

[quote]So, is there any way to declare and them “call” vectors by using some kind of char + sprinft syntax??[/quote]No, not in C++. You could try to pull this off using CPP macros but more likely you may want to investigate using a map from string to vector to implement what you need (i.e. I don’t understand how you plan on using this nor do I see (for now) how this would actually help to have ‘mutual’ name for the variable in your code … maybe you could expand on how you want to use them in a larger context I might be able to better help.