What is a good way to convert vector<string>
line to vector<vector <double> >
d?
I have 500x9 vector string data reading from a file,
vector<string> line;
I need to convert this string vector into 2D vector array of size (500 rows, 9 columns)
vector<vector <double> > d;
Code:
using namespace std;
int main()
{
/// read file data ///
std::ifstream myfile;
myfile.open("somefile.txt");
std::vector<string> lines;
std::string str;
while(getline(myfile,str))
lines.push_back(str);
myfile.close();
std::vector< std::vector<double> > data;
/// convert string to double ///
std::transform(lines.begin(), lines.end(), data.begin(), std::stod);
}