lundi 30 mai 2016

std::atof or std::stof (c++11) unable to convert properly ("1.24")

I'm a little bit frustrated after I've found this strange atof/stof behavior

double bg = std::stof("1,24");
std::cerr<<"comma: "<<bg<<std::endl;
bg = std::stof("1.24");
std::cerr<<"dot: "<<bg<<std::endl;

when I change the string format, from comma to dot, this is what happens:

comma: 1.24
dot: 1

has anyone encountered this problem? thanks

bart

Aucun commentaire:

Enregistrer un commentaire