2D array size problem loading from csv file
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;
auto pre_num_row = data_length.nc();
static const int num_row = 73;//data_length.nr();
static const int num_column = 74496; //data_length.nc();
std::cout << num_row << "\n";
std::cout << num_column << "\n";
double data[73][74496];
for (int row = 0; row < 73; ++row)
{
std::string line;
std::getline(file, line);
if (!file.good())
break;
std::stringstream iss(line);
for (int col = 0; col < 74496; ++col)
{
std::string val;
std::getline(iss, val, ',');
if (!iss.good())
break;
std::stringstream convertor(val);
convertor >> data[row][col];
}
}
std::cout << data[1][1] << "\n";
}
Hello, My name is Q. I want to read a csv file (here the name of the file is NAimg_20101026_145727.csv) and load the data to data array. The size of row and column of the file is 73 and 74496. Therefore, I need double data[73][74496] array. It makes error. When I make a small array, for example, double data[10][20], there is no error. Do you know what is the problem?
I have one more issue. I want to read the size of row and column from csv file and automatically decide the size of double data[row][column]. Therefore, I tried to use data_length.nc(); to decide the row and column of the double data size. Do you know how to decide the size of double data[row][column] from csv file? Thanks
from Recent Questions - Stack Overflow https://ift.tt/2WRAq48
https://ift.tt/eA8V8J
Comments
Post a Comment