Multi-dim TString array

I always had this problem of not knowing how to get multi-dimensional TString arrays to work. I’d like to do something like this:
TString sample[3][2] = {{“Sge90”, “Slt90p20”}, {“das”, “kp”}, {“tmk”, “fds”}};
Then i can acces the TStrings extremely easy in some loop.

This kind of functionality is there e.g. for TH1, but I never found how to do this for TString.

Is there a reason for this? Or did I miss an obvious implementation? Any help welcome.

daan

#include "Riostream.h"
#include <vector>
#include <TString.h>

void tmp()
{
	vector< vector<TString> > sample;
	vector<TString> a;
	a.clear();
	a.push_back("Sge90");
	a.push_back("Slt90p20");
	sample.push_back(a);

	a.clear();
	a.push_back("das");
	a.push_back("kp");
	sample.push_back(a);

	a.clear();
	a.push_back("tmk");
	a.push_back("fds");
	sample.push_back(a);

	for ( size_t i=0; i<sample.size(); i++ )
	{
		for ( size_t j=0; j<sample[i].size(); j++ )
		{
			cout<<"sample["<<i<<"]["<<j<<"]="<<sample[i][j]<<endl;	
		}
	}
}

root -l tmp.c++

result:

Aaah, and only after all this time I found out that char* do the job instead of TString. :slight_smile: The following is a bit less flexible than previous example (no use of vectors), but good enough for most of my applications.

[code]
void tmp2() {

char* sample[3][2] = { {“Sge90”, “Slt90p20”}, {“das”, “kp”}, {“tmk”, “fds”} };
for ( size_t i=0; i<3; i++ ) {
for ( size_t j=0; j<2; j++ ) {
cout<<“sample[”<<i<<"]["<<j<<"]="<<sample[i][j]<<endl;
}
}

return;
}[/code]

daan