it is possible to do something like that
std::string str = "127,8";
double x = boost::lexical_cast<double>(str);
I tried it but it throws an exception, do u have a simple way to do such cast using boost ?
it is possible to do something like that
std::string str = "127,8";
double x = boost::lexical_cast<double>(str);
I tried it but it throws an exception, do u have a simple way to do such cast using boost ?
You can use a custom locale that uses ,
for the decimal point. Code taken and modified from https://stackoverflow.com/a/7277333/4117728
#include <iostream>
#include <boost/lexical_cast.hpp>
class comma_numpunct : public std::numpunct<char>
{
protected:
virtual char do_decimal_point() const
{
return ',';
}
};
int main(int argc, char *argv[]) {
std::string str = "127,8";
std::locale comma_locale(std::locale(), new comma_numpunct());
std::locale::global(comma_locale);
double x = boost::lexical_cast<double>(str);
}