I’d like to convert a string to a float in C++. currently trying to use atof. Any suggestions are much appreciated.
they are coming in as:
2.22,2.33,2.44,2.55
at the end, I’d like the temp array to look like:
Temp[4] = {2.22,2.33,2.44,2.55}
getline (myfile,line);
t_tokenizer tok(line, sep);
float temp[4];
int counter = 0;
for (t_tokenizer::iterator beg = tok.begin(); beg != tok.end(); ++beg)
{
temp[counter] = std::atof(* beg);
counter++;
}
You can always use boost’s
lexical_cast, or the non-boost equivalent: