我有一個包含算術的輸入文件(ASCII),例如:
TEST;0.0;0.0+0.1;0.0+0.2
在算術表達式中使用boost :: lexical_cast
我可以讀取字符串並相應地拆分它,所以我已經有了std::string
的元素。現在我想用boost::lexical_cast<double>
存儲它在雙,相當於像一個表達式:
double d = boost::lexical_cast<double>("0.0+0.1");
然而,加速拋出
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
等待,您希望lexical_cast爲您計算0.0 + 0.1? – PlasmaHH 2012-07-17 14:33:07
你的表情有多複雜?用圓括號嵌套任意深度?你想要實現哪些操作符? – robert 2012-07-17 14:34:21
@PlasmaHH是的,我認爲是。要問的問題太多了? – Gunnar 2012-07-17 14:43:31