I am trying to convert data from a .dat file to a ttree in a ROOT macro, and need to check to see if some of the data are floats, and if so, convert them to such.
I have currently
std::istringstream templine(line);
std::vector<float> sub_lines;
std::string temp1;
std::cout << "might it be from the reuse of line?" << std::endl;
while(getline(templine, temp1, ' ')){
std::cout<<temp1<<std::endl;
try{
if(line.find("#")==std::string::npos){
sub_lines.push_back(std::stof(temp1.c_str()));
j++;
}
}
where line is read in from the file, but on running using the .x command in root, I get an error that says “function stof(temp1.c_str()) is not defined in this scope”. I get the same error with or without the std:: and I am certian the data are reading in correctly
And an additional warning: you need to use the 2-argument version of stof to really ensure you have a float. stof will happily convert “1hello” to 1.0f (without throwing).