I'm glad that was useful.
I didn't know what sort of data was in the input file, I just saw you had an array of strings.
If you want to do any sort of calculations with the string, it needs to first be converted into a numeric type, such as
double
or
int
.
There are several different ways to do that. You could use the functions
atof
or
atoi
http://www.cplusplus.com/reference/cstdlib/atof/
http://www.cplusplus.com/reference/cstdlib/atoi/
The code might be something like this:
double n = atof(str[1][ix].c_str());
Note the use of
.c_str()
to convert the C++ string to a plain character string.
You might instead use a stringstream.
1 2 3
|
istringstream ss(str[1][ix]);
double d;
ss >> d;
|
I find stringstream very useful, it's worth becoming familiar with.
http://www.cplusplus.com/reference/sstream/
Note - if all of the data in the text file consists of numbers, then you should probably not be using an array of strings to handle them. Right from the start, read and store each value as a number. (But if you have a mixture of strings and numbers, then there are several different ways to look at this).
Hope this helps.