我有一个带有算术的输入文件(ASCII),例如
TEST;0.0;0.0+0.1;0.0+0.2
我可以读取字符串并相应地拆分它,所以我已经有了std::string
. 现在我想用boost::lexical_cast<double>
双精度存储它,类似于这样的表达式:
double d = boost::lexical_cast<double>("0.0+0.1");
但是,Boost抛出
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >'
what(): bad lexical cast: source type value could not be interpreted as target
有没有好办法,也许没有sscanf
?(如果sscanf
有能力做到这一点......)
TIA