read arithmetic expressions in .txt files

Hello everybody,

I would like read mathematical functions in .txt file.
Example :
on the first line, there is the expression "sin(5)"
on the second line, there is the expression 'exp(26)"
etc...

I would like read these expressions and store them in different variables in my main C++ code in order to use them later.

Is there someone that can help me?

Sorry for my approximative english...

Thaks a lot for your explanation.
Last edited on
1 Read the function into a string.
2 Split the string into text and number:
2.1 find the ( and ) with function string::find.
2.2 create two strings: one from begining to ( and another from (+1 to )
3 ...profit!
Hi,

ok thanks a lot for your answer... Could you write an example ?!
I'm not familiar with such manipulations...

Thank you very much!
I bet you can do the 1
then
1
2
3
4
5
string input = "sin(5)";
int p1 = input.find('(', 0);
int p2 = input.find(')', p1+1);
string text(input, 0, p1);
string num(input, p1+1, p2);

now text should be "sin" and num should be "5"
you may want to convert string num into int.
see http://www.cplusplus.com/articles/numb_to_text/ for that
you bet well ;-)

Thank you for the example...
Topic archived. No new replies allowed.