From String to Function [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'd like to know if there is a way to transform a string into a function em c++. For example if I have the string: "x+y" it'd create the function and by replacing x and y, get the value of it.
In Java there is this API https://www.objecthunter.net/exp4j/index.html, so I was wondering if there is something similar.

There are many possible methods one could use to transform a string into a "function". Many of those involve parsing the string and building a function-like object out of it.
A lightweight and portable solution would be to use ExprTk, a mathematical expression library developed by Arash Partow.
The main page contains various usage examples.

Related

String comparison function (c++) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am looking for a function to compare the two strings. A functional similar to strcmp in CString with the difference that takes two strands in the input.
You can use std::string::compare (it returns 0 if values are the same). Also be aware that in fact you can use strcmp in c++, but if you want modern c++ version i would go with std::string::compare.

Why does regex not work for searching json? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a lot of different documents in which I want to find certain JSON, here is an example (regex101).
regex: {\"columns.*]}
I expect to get json like this:
{"columns":["1",{"title":"Bad Boys For Life","value":"Bad Boys For Life"},"2","686.5","764.5","874","877","897","937",{"value":"686.5","isMeta":true},{"isMeta":true,"value":"764.5"},{"isMeta":true,"value":"874"},{"isMeta":true,"value":"877"},{"value":"897","isMeta":true},{"isMeta":true,"value":"937"},"850398",{"value":"937","isMeta":true}]}
But that doesn't work, why?
Your regex misses a global flag so it only produces one match.
Here's the fixed version: https://regex101.com/r/o0j2Sk/2/
The reason you're getting downvoted though is that you should not use regex to parse JSON. It is extremely easy to parse JSON properly with any language, so that's strongly recommended to everybody.

How to implement a parser in C for xml based structured language? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need to implement a simple parser in C (or C++ if C is discouraged for this application) that will read a xml file which will only contain a few elements (that's why called it xml based) i.e., only 4 root elements and and less than 5 child elements totally.
Is it easy to implement or should I use a library like expat? And if it is possible can someone tell me how I can about the process?
Use libxml or libexpat.
There are millions, trillions of examples you can find on net, or even at StackOverflow.
Have a look at this: How can libxml2 be used to parse data from XML?
or use google protobuf,
although it is not xml-based, but it fast.

Turning a string that contains a equation into an integer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I would like to be able to convert a string such as "(5+6)*6" and get the resulting integer from that equation. It is important that it starts out as a string.
You can use library fastmathparser for c++.
In link is example how use this library.
If you really want write alone this parser, I recomended use Shunting-yard algorithm

which class can be used in c++ in replacement of streamtokenizer in java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to write a program for assignment statement interpreter in c++.I have implemented the program in java.I need to tokenize the input which consists of numbers,words and operators(=,+,-,*,/).I used a stream Tokenizer in java to tokenize and parse the input.I need functions like 1.control going to next token 2.type of the current token(number or word).like functions nexttoken() and ttype() nval() sval() pushback() in java. please help me out of this.
Boost::Tokenizer is a pretty versatile tokenizer for C++ and should easily handle your case.