以下のコードを使用して、複数の .dat ファイルを 2D ベクトルに読み取り、トークン値を出力しました。ただし、コンパイルが完了した後にすべてのトークン値がメモリに格納されるかどうか、およびtoken[3][27]
次の処理の例として特定の要素をどのように参照できるかを知る必要があります。
for (int i = 0; i < files.size(); ++i) {
cout << "file name: " << files[i] << endl;
fin.open(files[i].c_str());
if (!fin.is_open()) {
cout<<"error"<<endl;
}
std::vector<vector<string>> tokens;
int current_line = 0;
std::string line;
while (std::getline(fin, line))
{
cout<<"line number: "<<current_line<<endl;
// Create an empty vector for this line
tokens.push_back(vector<string>());
//copy line into is
std::istringstream is(line);
std::string token;
int n = 0;
//parsing
while (getline(is, token, DELIMITER))
{
tokens[current_line].push_back(token);
cout<<"token["<<current_line<<"]["<<n<<"] = " << token <<endl;
n++;
}
cout<<"\n";
current_line++;
}
fin.clear();
fin.close();
}
ファイルごとに 2D ベクトルを作成する必要がありますか? C++ の実行時にそれを達成できますか?