Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Questions regarding functions (http://www.go4expert.com/forums/questions-regarding-functions-t19666/)

gabuchia 4Oct2009 21:33

Questions regarding functions
Good day guys, this is my first time posting, so if there is anything I should know about this particular forum, please do let me know!

I have tried searching on the internet, but do you guys know what does this line do?

istringstream is(Expr);

if(Expr.at(i)=='(') p++;

return Value_Of_Expr(Expr.substr(0,i))+Value_Of_Expr(Expr .substr(i+1,Expr.length()-i-1));

These three lines have something I don't understand, such as :

istringstream is(XX) - What does it do?

if(Exr.at(i)=='(') p++;

return Value_Of_Expr(Expr.substr(0,i))+Value_Of_Expr(Expr.substr(i+1,Expr.length()-i-1));

xpi0t0s 5Oct2009 03:58

Re: Questions regarding functions
When you post, there are posting guidelines, including how to post code. READ THEM PLEASE.
They're not easy to miss.

istringstream is(XX) creates an istringstream object named is, using a constructor that takes an XX as its argument, so it creates an istringstream from an XX.


if(Exr.at(i)=='(') p++;
The brackets may be confusing you; let's add some space to clarify:

if(    Exr.at(i)  ==  '('    ) p++;
So this calls Exr.at, passing in i, which returns a character, which the == compares with an open bracket. So this appears to be doing some kind of analysis of nested expressions where brackets are used for nesting.

gabuchia 6Oct2009 18:12

Re: Questions regarding functions
Thank you for helping me out with that! I'm sorry I did not post a little chunk of code here because I thought if I could comprehend those few lines, I would be able to understand it.

istringstream is(Expr);
double value=0.0;
is >> value;
return value;

thank you for helping me out with my little project here, I appreciate that!

All times are GMT +5.5. The time now is 02:00.