sscanf を使用して、この行の整数 (layer、ieta、depth) を取得するのを手伝ってくれる人はいますか? (1)の前に別の関数を使用しましたが、機能しました。しかし、代わりに何か新しいことを試してみたかっただけで(2)、プログラムは変数ごとに0を返します。
(1)
Int_t getIetaFromHistName (string histName)
{
Int_t IetaPos = histName.find("_Ieta"); //find position of Ieta & return as integer
Int_t IphiPos = histName.find("_Iphi");
return atoi(histName.substr(IetaPos+5,IphiPos-IetaPos-5).c_str()); //reconstruct the string (post of 1st char to be copied, string length)
};
(2)
char histoName [100] = event2->GetName();
sscanf(histoName,"H2_HB_PHI12_LAYER%d_SRCTUBE_Ieta%d_Iphi12_Depth%d",&layNo,&ietaNo,&depthNo); //string histoName = H2_HB_PHI12_LAYER10_SRCTUBE_Ieta1_Iphi12_Depth1
printf("Layer= %d , Ieta= %d , Depth= %d\n",layNo,ietaNo,depthNo);