Hi,Philippe,
Thank for your answer. I changed my program to parse the NaN string into float. It is still not working because of the numeric_limits stuff.
Here are the details:
To simplify the matter, I use the following data(test.dat)
1
2
nan
My program is
bool string2double(char* digit, double& result) {
int sign = 1;
result = 0;
// check sign
if (*digit == ‘-’) {
sign = -1;
digit++;
}
//— get integer portion
while (*digit >= ‘0’ && *digit <=‘9’) {
result = (result * 10) + *digit-‘0’;
digit++;
}
//— get decimal point and fraction, if any.
if (*digit == ‘.’) {
digit++;
double scale = 0.1;
while (*digit >= ‘0’ && *digit <=‘9’) {
result += (*digit-‘0’) * scale;
scale *= 0.1;
digit++;
}
}
//— error if we’re not at the end of the number
if (*digit != 0) {
return false;
}
//— set to sign given at the front
result = result * sign;
return true;
}
void treetest()
{
gROOT->Reset();
TTree* pMytree = new TTree(“SimpleTree”,“An example of tree”);
//Long64_t nlines = pMytree->ReadFile(“testdata.dat”,“x:y”);
//printf(“found %lld points\n”,nlines);
ifstream in(“test.dat”);
if(!in)
cout<<“Cann’t open file”<<endl;
cout<<“Here is OK”<<endl;
string s;
double f=0.0;
// float x,y;
float x;
pMytree->Branch(“x”,&x,“x/F”);
// pMytree->Branch(“y”,&y,“y/F”);
while(!in.eof()){
// in>>x>>y;
getline(in,s);
//if(from_string(f,s,std::dec))
//if(EOF==strtod(s,NULL))
if (string2double(s.c_str(),f))
x=f;
else
x=std::numeric_limits::quiet_NaN();
pMytree->Fill();
}
// pMytree->Fill();
// pMytree->Show(1);
pMytree->Draw(“x”);
pMytree->Print();
//pMytree->Write();
}
The error messages are as follows:
Error: Symbol numeric_limits is not defined in current scope treetest.C:85:
Error: Symbol float is not defined in current scope treetest.C:85
I can use g++ to compile programs with numeric_limits. I added the limits header files into the code and it did not work either.
How can I correct this? Thank you very much.
regards,
gma