How do I easily convert a string containing two floats separated by a comma into a complex?
For instance:
string s = "123,5.3";//input
complex<float> c(123,5.3);//output/what I need
Is there an simpler/faster way than to split the string, read the two values and return thecomplex<float>?
Just add the parentheses and the default
operator>>will do it for you:PS. Funny how everyone’s style is slightly different, although the answers are the same.
If you are ready to handle exceptions, this can be done with boost, too: