Oct 3, 2009 at 5:29pm UTC
What's happening here?
1 2 3
string temp("(" +coef_); // Why does string temp("("+coef_+")*X^" + exp_); not work?
temp+=")*X^" + exp_;
return temp;
(coef_ and exp_ are variables within a class. coef_ is an integer, and exp_ is unsigned)
Thanks in advance!
Last edited on Oct 3, 2009 at 5:30pm UTC
Oct 3, 2009 at 5:31pm UTC
You can't add integers to a string, use streams:
1 2 3
stringstream temp;
temp << "(" << coef_<< ")*X^" << exp_;
return temp.str();
Last edited on Oct 3, 2009 at 5:32pm UTC
Oct 3, 2009 at 5:39pm UTC
Well, actually I can.
string temp("(" + coef_ ) ;
WORKS
however, i can't use more than one +.
(by the way, i can't get your code to work :-( )
Last edited on Oct 3, 2009 at 5:41pm UTC
Oct 3, 2009 at 5:50pm UTC
You need to #include<sstream>
BTW "something"+number means pointer+offset which will give you problems
Oct 3, 2009 at 6:18pm UTC
You're right. I made a small program, and "something"+number leads to strange behaviours (Such as not printing anything at all). Plus, I'll try to use sstream
Thanks a lot. I'm marking this as answered.
Last edited on Oct 3, 2009 at 6:19pm UTC