I am trying to read the content of the .csv file using 1D\_array instead of using 1D\_vector, and 2D arrays instead of 2D vector. Below is my code of reading the .csv file using vector and its works correctly.
But my professor asked me to use arrays instead of vectors for further optimization issues. I have tried to use arrays but still can't get it.
Can anyone help please?

```
    //functoin to read dataset from .csv file.
bool read_data_set(string filename, vector<vector<int>>& vec_X_dataset, vector<int>& vec_Y_dataset) {
    int field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11,
        field12, field13, field14, field15, field16, field17, field18, field19, field20, field21;
    char comma;
    string line;
    ifstream myfile(filename);
    if (myfile.is_open())
    {
       while (myfile
            >> field0 >> comma
            >> field1 >> comma
            >> field2 >> comma
            >> field3 >> comma
            >> field4 >> comma
            >> field5 >> comma
            >> field6 >> comma
            >> field7 >> comma
            >> field8 >> comma
            >> field9 >> comma
            >> field10 >> comma
            >> field11 >> comma
            >> field12 >> comma
            >> field13 >> comma
            >> field14 >> comma
            >> field15 >> comma
            >> field16 >> comma
            >> field17 >> comma
            >> field18 >> comma
            >> field19 >> comma
            >> field20 >> comma
            >> field21)
        {

       vector<int> inner_vec{ field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11,
      field12, field13, field14, field15, field16, field17, field18, field19, field20 };
            vec_X_dataset.push_back(inner_vec);
            vec_Y_dataset.push_back(field21);

        }
       myfile.close();

    }
    else {
        cout << "Unable to open file";
        return true;
    }
    return false;
}

int main() {

    cout << endl << "KNN  K-Nearest-Neighbors in C++" << endl << endl;
    cout << "please insert the value of K ";
    cin >> k;

    // Read dataset from file.
    string filename = ".//Cleaned Covid Dataset.csv";
    vector<vector<int>> vec_X_dataset{};
    vector<int> vec_Y_dataset{};
    bool error = read_data_set(filename, vec_X_dataset, vec_Y_dataset);
    if (error) {
        cout << "Exiting with error while reading dataset file " << filename << endl;
        exit(-1);
    }

```

bool read\_data\_set(string filename, int (&array\_X\_dataset)[5430][20], int (&array\_Y\_dataset)[5430]) {
int field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11,
field12, field13, field14, field15, field16, field17, field18, field19, field20, field21;
char comma;
string line;

```
ifstream myfile(filename);
if (myfile.is_open())
{
    while (myfile
        >> field0 >> comma
        >> field1 >> comma
        >> field2 >> comma
        >> field3 >> comma
        >> field4 >> comma
        >> field5 >> comma
        >> field6 >> comma
        >> field7 >> comma
        >> field8 >> comma
        >> field9 >> comma
        >> field10 >> comma
        >> field11 >> comma
        >> field12 >> comma
        >> field13 >> comma
        >> field14 >> comma
        >> field15 >> comma
        >> field16 >> comma
        >> field17 >> comma
        >> field18 >> comma
        >> field19 >> comma
        >> field20 >> comma
        >> field21)
    {

        /*vector<int> inner_vec{field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11,
   field12, field13, field14, field15, field16, field17, field18, field19, field20 };
        vec_X_dataset.push_back(inner_vec);
        vec_Y_dataset.push_back(field21);*/

        cout << field21 << endl; 

         for (size_t i = 0; i < 5430; i++)
        {
            array_Y_dataset[i] = field21;
        }

    }
    for (size_t i = 0; i < 5430; i++)
    {
        cout<< i << " "<< array_Y_dataset[i] << endl;
    }
  myfile.close();

}
else {
    cout << "Unable to open file";
    return true;
}
return false;

```

}