I made this code based on the suggestion from Ted. I want to read data from csv file and load the data on data array. The code the above does not work. Do you know the problem?
int main()
{
auto base_dir = fs::current_path();
auto dataset_1 = data_names_1;
auto dataset_name = base_dir / "NAimg_20101026_145727.csv";
//double data[10][3];
std::ifstream file(dataset_name);
matrix<DataType> data_length;
//file >> data_length;
// create a 2D vector from nr() and nc()
std::vector<std::vector<double>> data(data_length.nr(),
std::vector<double>(data_length.nc()));
// fill the 2D vector with data from the file using range-based for loops:
for (auto& row : data) {
for (auto& col : row) {
file >> col;
}
}
if (file) {
// successfully read the data from the file
std::cout << data[1][1] << '
';
}
else {
std::cout << "failed extracting data from file
";
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…