I am trying to convert an array that contains string into a float. Every string at index [j][2] will be a number which must be converted into a float. i is an int that contains the total number of "rows" of the array. First, I need to multiply it by 8 and then divide by 10, then convert it into a string and store it back into the array. I want to convert it into a float again at a later time but I need a record of which index each float belongs to. So I need a reliable method of converting string into floats. The following fails and gives me this error message:
for (int j = 0; j < i; j++) {
float wow = strtof(array[j][2]);
array[j][3] = (wow + float(i/10)*8);
}
Error:
cannot convert ‘std::string {aka std::basic_string}’ to ‘const char*’ for argument ‘1’ to ‘float strtof(const char*, char**)’
Variations of strtof
like stof
and atof
give me the same error.