Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to split a string and convert it into an array of floats

I want to convert the string into a float array
They are saved as double strings
Thanks for your help

string str ="7.13566982194977e-15,1.639519203260036e-43,4.149314136725479e-8,7.987401246651457e-44,7.11674964700695e-15,1.639519203260036e-43,4.515206005147025e+27"

std::vector<float> result 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

std::istringstream(str);     // #include <sstream>
std::string s;
std::vector<float> result;
while (std::getline(str, s, ','))
{
    float f = atof(s.c_str());
    result.push_back(f);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading