将字符串转换为数学计算 [英] Convert string to mathematical evaluation
问题描述
好的,所以我想做的是使用字符串作为输入(例如16 * 12 + 25),将其转换为计算机可以理解并返回评估值的数学计算。我可能自己写这个,但它很可能需要一段时间,最后,它仍然不会结束,我想要的,除非我想要更多的时间。
Okay, so what I want to do is to use a string as input (for instance "16*12+25"), convert it to a mathematical evaluation that the computer can comprehend and return the evaluated value. I could probably write this myself, but it would most likely take quite a while and in the end, it still wouldn't end up as good as I'd like it to unless I want to put even more time into it.
所以我的问题是,有没有任何脚本,库或api,你知道可以做这个C ++?我发现一些为java,python和.NET。但是我不使用任何这些语言,我想在C ++中保持尽可能长(希望贯穿整个项目)。你有什么好的想法或链接?
So my question is, is there any script, library or api that you know can do this for C++? I have found some for both java, python and .NET. But I am not working with any of these languages and I would like to remain within C++ for as long (hopefully throughout the entire project) as possible. Do you have any good ideas or links?
推荐答案
我发现我在找什么!可下载的源代码是C ++和CodeBlocks项目。您可以在这里找到: http://www.speqmath.com/tutorials/expression_parser_cpp/index.html
I found what I was looking for! The downloadable source is C++ and a CodeBlocks project. You can find it here: http://www.speqmath.com/tutorials/expression_parser_cpp/index.html
Jared推荐的一个更复杂的表达式解析器: http://www.partow.net/programming/exprtk/index.html
A far more sophisticated expression parser recommended by Jared: http://www.partow.net/programming/exprtk/index.html
这篇关于将字符串转换为数学计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!