vector<string>
line をvector<vector <double> >
dに変換する良い方法は何ですか?
ファイルから500x9のベクトル文字列データを読み取っていますが、
vector<string> line;
この文字列ベクトルをサイズ (500 行、9 列) の 2D ベクトル配列に変換する必要があります。
vector<vector <double> > d;
コード:
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);
}